arkruntime 0.1.0__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.
Files changed (714) hide show
  1. arkruntime/__init__.py +11 -0
  2. arkruntime/_base_client.py +1373 -0
  3. arkruntime/_client.py +585 -0
  4. arkruntime/_compat.py +265 -0
  5. arkruntime/_constants.py +55 -0
  6. arkruntime/_exceptions.py +188 -0
  7. arkruntime/_files.py +122 -0
  8. arkruntime/_legacy_response.py +438 -0
  9. arkruntime/_managed_agents_serialize.py +55 -0
  10. arkruntime/_models.py +733 -0
  11. arkruntime/_qs.py +164 -0
  12. arkruntime/_request_options.py +118 -0
  13. arkruntime/_resource.py +41 -0
  14. arkruntime/_response.py +599 -0
  15. arkruntime/_streaming.py +460 -0
  16. arkruntime/_types.py +207 -0
  17. arkruntime/_utils/__init__.py +144 -0
  18. arkruntime/_utils/_key_agreement.py +217 -0
  19. arkruntime/_utils/_logs.py +28 -0
  20. arkruntime/_utils/_model_breaker.py +87 -0
  21. arkruntime/_utils/_streams.py +17 -0
  22. arkruntime/_utils/_transform.py +463 -0
  23. arkruntime/_utils/_typing.py +157 -0
  24. arkruntime/_utils/_utils.py +473 -0
  25. arkruntime/common/__init__.py +6 -0
  26. arkruntime/common/_parsing/__init__.py +31 -0
  27. arkruntime/common/_parsing/_completions.py +272 -0
  28. arkruntime/common/_parsing/_responses.py +174 -0
  29. arkruntime/common/_pydantic.py +166 -0
  30. arkruntime/common/_tools.py +85 -0
  31. arkruntime/common/streaming/__init__.py +4 -0
  32. arkruntime/common/streaming/_deltas.py +68 -0
  33. arkruntime/common/streaming/chat/__init__.py +49 -0
  34. arkruntime/common/streaming/chat/_completions.py +732 -0
  35. arkruntime/common/streaming/chat/_events.py +96 -0
  36. arkruntime/common/streaming/chat/_types.py +28 -0
  37. arkruntime/pagination.py +128 -0
  38. arkruntime/resources/__init__.py +75 -0
  39. arkruntime/resources/agents/__init__.py +3 -0
  40. arkruntime/resources/agents/agents.py +372 -0
  41. arkruntime/resources/batch/__init__.py +6 -0
  42. arkruntime/resources/batch/_utils.py +156 -0
  43. arkruntime/resources/batch/batch.py +40 -0
  44. arkruntime/resources/batch/chat/__init__.py +6 -0
  45. arkruntime/resources/batch/chat/chat.py +22 -0
  46. arkruntime/resources/batch/chat/completions.py +217 -0
  47. arkruntime/resources/batch/embeddings.py +150 -0
  48. arkruntime/resources/batch/multimodal_embeddings.py +160 -0
  49. arkruntime/resources/beta/__init__.py +4 -0
  50. arkruntime/resources/beta/beta.py +73 -0
  51. arkruntime/resources/beta/chat/__init__.py +13 -0
  52. arkruntime/resources/beta/chat/chat.py +23 -0
  53. arkruntime/resources/beta/chat/completions.py +356 -0
  54. arkruntime/resources/chat/__init__.py +7 -0
  55. arkruntime/resources/chat/chat.py +23 -0
  56. arkruntime/resources/chat/completions.py +242 -0
  57. arkruntime/resources/content_generation/__init__.py +7 -0
  58. arkruntime/resources/content_generation/content_generation.py +21 -0
  59. arkruntime/resources/content_generation/tasks.py +331 -0
  60. arkruntime/resources/embeddings/__init__.py +6 -0
  61. arkruntime/resources/embeddings/embeddings.py +140 -0
  62. arkruntime/resources/encryption.py +187 -0
  63. arkruntime/resources/environments/__init__.py +3 -0
  64. arkruntime/resources/environments/environments.py +216 -0
  65. arkruntime/resources/files/__init__.py +6 -0
  66. arkruntime/resources/files/files.py +401 -0
  67. arkruntime/resources/images/__init__.py +10 -0
  68. arkruntime/resources/images/images.py +152 -0
  69. arkruntime/resources/memory_stores/__init__.py +7 -0
  70. arkruntime/resources/memory_stores/memories.py +262 -0
  71. arkruntime/resources/memory_stores/memory_stores.py +223 -0
  72. arkruntime/resources/multimodal_embeddings/__init__.py +9 -0
  73. arkruntime/resources/multimodal_embeddings/multimodal_embeddings.py +150 -0
  74. arkruntime/resources/responses/__init__.py +8 -0
  75. arkruntime/resources/responses/input_items.py +241 -0
  76. arkruntime/resources/responses/responses.py +467 -0
  77. arkruntime/resources/sessions/__init__.py +24 -0
  78. arkruntime/resources/sessions/session_events.py +336 -0
  79. arkruntime/resources/sessions/session_resources.py +89 -0
  80. arkruntime/resources/sessions/session_threads.py +275 -0
  81. arkruntime/resources/sessions/sessions.py +331 -0
  82. arkruntime/resources/skills/__init__.py +3 -0
  83. arkruntime/resources/skills/skills.py +112 -0
  84. arkruntime/resources/tokenization/__init__.py +9 -0
  85. arkruntime/resources/tokenization/tokenization.py +131 -0
  86. arkruntime/resources/vaults/__init__.py +4 -0
  87. arkruntime/resources/vaults/credentials.py +253 -0
  88. arkruntime/resources/vaults/vaults.py +197 -0
  89. arkruntime/types/__init__.py +7 -0
  90. arkruntime/types/agent/__init__.py +56 -0
  91. arkruntime/types/agent/_init_extras_shim.py +12 -0
  92. arkruntime/types/agent/agent.py +86 -0
  93. arkruntime/types/agent/agent_ref.py +32 -0
  94. arkruntime/types/agent/agent_ref_type.py +18 -0
  95. arkruntime/types/agent/agent_skill_ref.py +32 -0
  96. arkruntime/types/agent/create_agent_request.py +65 -0
  97. arkruntime/types/agent/delete_agent_response.py +20 -0
  98. arkruntime/types/agent/list_agents_response.py +32 -0
  99. arkruntime/types/agent/mcp_server.py +30 -0
  100. arkruntime/types/agent/mcp_server_type.py +16 -0
  101. arkruntime/types/agent/model_config.py +28 -0
  102. arkruntime/types/agent/model_speed.py +18 -0
  103. arkruntime/types/agent/multiagent_config.py +29 -0
  104. arkruntime/types/agent/multiagent_type.py +16 -0
  105. arkruntime/types/agent/permission_policy.py +22 -0
  106. arkruntime/types/agent/permission_policy_type.py +18 -0
  107. arkruntime/types/agent/skill_ref_type.py +19 -0
  108. arkruntime/types/agent/tag.py +26 -0
  109. arkruntime/types/agent/tool_config.py +32 -0
  110. arkruntime/types/agent/tool_default_config.py +28 -0
  111. arkruntime/types/agent/tool_item.py +57 -0
  112. arkruntime/types/agent/update_agent_request.py +70 -0
  113. arkruntime/types/chat/__init__.py +212 -0
  114. arkruntime/types/chat/_init_extras_shim.py +73 -0
  115. arkruntime/types/chat/chat_completion_choice_logprobs.py +20 -0
  116. arkruntime/types/chat/chat_completion_content_part.py +32 -0
  117. arkruntime/types/chat/chat_completion_content_part_audio.py +23 -0
  118. arkruntime/types/chat/chat_completion_content_part_audio_input_audio.py +30 -0
  119. arkruntime/types/chat/chat_completion_content_part_audio_input_audio_param.py +25 -0
  120. arkruntime/types/chat/chat_completion_content_part_audio_param.py +22 -0
  121. arkruntime/types/chat/chat_completion_content_part_file.py +21 -0
  122. arkruntime/types/chat/chat_completion_content_part_file_file.py +30 -0
  123. arkruntime/types/chat/chat_completion_content_part_file_file_param.py +25 -0
  124. arkruntime/types/chat/chat_completion_content_part_file_param.py +22 -0
  125. arkruntime/types/chat/chat_completion_content_part_image.py +23 -0
  126. arkruntime/types/chat/chat_completion_content_part_image_image_url.py +33 -0
  127. arkruntime/types/chat/chat_completion_content_part_image_image_url_param.py +28 -0
  128. arkruntime/types/chat/chat_completion_content_part_image_param.py +22 -0
  129. arkruntime/types/chat/chat_completion_content_part_param.py +29 -0
  130. arkruntime/types/chat/chat_completion_content_part_text.py +22 -0
  131. arkruntime/types/chat/chat_completion_content_part_text_param.py +19 -0
  132. arkruntime/types/chat/chat_completion_content_part_video.py +23 -0
  133. arkruntime/types/chat/chat_completion_content_part_video_param.py +22 -0
  134. arkruntime/types/chat/chat_completion_content_part_video_video_url.py +36 -0
  135. arkruntime/types/chat/chat_completion_content_part_video_video_url_param.py +30 -0
  136. arkruntime/types/chat/chat_completion_message_content.py +17 -0
  137. arkruntime/types/chat/chat_completion_message_content_param.py +15 -0
  138. arkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
  139. arkruntime/types/chat/chat_completion_message_tool_call_chunk.py +31 -0
  140. arkruntime/types/chat/chat_completion_message_tool_call_chunk_function.py +16 -0
  141. arkruntime/types/chat/chat_completion_message_tool_call_function.py +23 -0
  142. arkruntime/types/chat/chat_completion_message_tool_call_function_param.py +22 -0
  143. arkruntime/types/chat/chat_completion_message_tool_call_param.py +26 -0
  144. arkruntime/types/chat/chat_completion_named_tool_choice.py +21 -0
  145. arkruntime/types/chat/chat_completion_named_tool_choice_param.py +22 -0
  146. arkruntime/types/chat/chat_completion_request.py +129 -0
  147. arkruntime/types/chat/chat_completion_request_assistant_message.py +39 -0
  148. arkruntime/types/chat/chat_completion_request_assistant_message_param.py +36 -0
  149. arkruntime/types/chat/chat_completion_request_message.py +32 -0
  150. arkruntime/types/chat/chat_completion_request_message_param.py +29 -0
  151. arkruntime/types/chat/chat_completion_request_param.py +122 -0
  152. arkruntime/types/chat/chat_completion_request_system_message.py +25 -0
  153. arkruntime/types/chat/chat_completion_request_system_message_param.py +23 -0
  154. arkruntime/types/chat/chat_completion_request_tool_message.py +29 -0
  155. arkruntime/types/chat/chat_completion_request_tool_message_param.py +26 -0
  156. arkruntime/types/chat/chat_completion_request_user_message.py +29 -0
  157. arkruntime/types/chat/chat_completion_request_user_message_param.py +27 -0
  158. arkruntime/types/chat/chat_completion_response.py +52 -0
  159. arkruntime/types/chat/chat_completion_response_choice.py +36 -0
  160. arkruntime/types/chat/chat_completion_response_format.py +28 -0
  161. arkruntime/types/chat/chat_completion_response_format_json_schema.py +33 -0
  162. arkruntime/types/chat/chat_completion_response_format_json_schema_param.py +31 -0
  163. arkruntime/types/chat/chat_completion_response_format_param.py +27 -0
  164. arkruntime/types/chat/chat_completion_response_message.py +37 -0
  165. arkruntime/types/chat/chat_completion_role.py +16 -0
  166. arkruntime/types/chat/chat_completion_service_status.py +17 -0
  167. arkruntime/types/chat/chat_completion_stop.py +13 -0
  168. arkruntime/types/chat/chat_completion_stop_param.py +11 -0
  169. arkruntime/types/chat/chat_completion_stream_choice_logprobs.py +17 -0
  170. arkruntime/types/chat/chat_completion_stream_options.py +22 -0
  171. arkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
  172. arkruntime/types/chat/chat_completion_stream_response.py +34 -0
  173. arkruntime/types/chat/chat_completion_stream_response_choice.py +27 -0
  174. arkruntime/types/chat/chat_completion_stream_response_delta.py +36 -0
  175. arkruntime/types/chat/chat_completion_token_logprob.py +26 -0
  176. arkruntime/types/chat/chat_completion_token_logprob_top_logprob.py +17 -0
  177. arkruntime/types/chat/chat_completion_tool.py +20 -0
  178. arkruntime/types/chat/chat_completion_tool_choice.py +18 -0
  179. arkruntime/types/chat/chat_completion_tool_choice_function.py +13 -0
  180. arkruntime/types/chat/chat_completion_tool_choice_function_param.py +13 -0
  181. arkruntime/types/chat/chat_completion_tool_choice_param.py +16 -0
  182. arkruntime/types/chat/chat_completion_tool_param.py +20 -0
  183. arkruntime/types/chat/completion_tokens_details.py +16 -0
  184. arkruntime/types/chat/completion_usage.py +35 -0
  185. arkruntime/types/chat/error.py +28 -0
  186. arkruntime/types/chat/error_response.py +15 -0
  187. arkruntime/types/chat/finish_reason.py +16 -0
  188. arkruntime/types/chat/function_object.py +35 -0
  189. arkruntime/types/chat/function_object_param.py +38 -0
  190. arkruntime/types/chat/image_detail.py +16 -0
  191. arkruntime/types/chat/image_pixel_limit.py +16 -0
  192. arkruntime/types/chat/image_pixel_limit_param.py +17 -0
  193. arkruntime/types/chat/model_fallback_status.py +20 -0
  194. arkruntime/types/chat/moderation_hit_type.py +14 -0
  195. arkruntime/types/chat/parsed_chat_completion_shim.py +52 -0
  196. arkruntime/types/chat/parsed_function_tool_call_shim.py +29 -0
  197. arkruntime/types/chat/prompt_tokens_details.py +34 -0
  198. arkruntime/types/chat/reasoning_effort.py +19 -0
  199. arkruntime/types/chat/request_service_tier.py +15 -0
  200. arkruntime/types/chat/response_format_type.py +15 -0
  201. arkruntime/types/chat/response_service_tier.py +15 -0
  202. arkruntime/types/chat/thinking.py +17 -0
  203. arkruntime/types/chat/thinking_mode.py +15 -0
  204. arkruntime/types/chat/thinking_param.py +17 -0
  205. arkruntime/types/chat/tool_choice_mode.py +15 -0
  206. arkruntime/types/chat/tool_type.py +13 -0
  207. arkruntime/types/chat/tool_type_param.py +11 -0
  208. arkruntime/types/chat/video_image_pixel_limit.py +16 -0
  209. arkruntime/types/chat/video_image_pixel_limit_param.py +17 -0
  210. arkruntime/types/completion_usage.py +43 -0
  211. arkruntime/types/content_generation/__init__.py +66 -0
  212. arkruntime/types/content_generation/_init_extras_shim.py +12 -0
  213. arkruntime/types/content_generation/audio_role.py +16 -0
  214. arkruntime/types/content_generation/audio_url.py +16 -0
  215. arkruntime/types/content_generation/audio_url_param.py +14 -0
  216. arkruntime/types/content_generation/content_generation_task.py +125 -0
  217. arkruntime/types/content_generation/content_item.py +54 -0
  218. arkruntime/types/content_generation/content_item_param.py +46 -0
  219. arkruntime/types/content_generation/content_type.py +21 -0
  220. arkruntime/types/content_generation/create_content_generation_task_request.py +106 -0
  221. arkruntime/types/content_generation/create_content_generation_task_request_param.py +83 -0
  222. arkruntime/types/content_generation/create_content_generation_task_response.py +16 -0
  223. arkruntime/types/content_generation/draft_task.py +16 -0
  224. arkruntime/types/content_generation/draft_task_param.py +14 -0
  225. arkruntime/types/content_generation/image_role.py +20 -0
  226. arkruntime/types/content_generation/image_url.py +16 -0
  227. arkruntime/types/content_generation/image_url_param.py +14 -0
  228. arkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
  229. arkruntime/types/content_generation/reasoning_effort.py +16 -0
  230. arkruntime/types/content_generation/task_content.py +30 -0
  231. arkruntime/types/content_generation/task_error.py +20 -0
  232. arkruntime/types/content_generation/task_status.py +21 -0
  233. arkruntime/types/content_generation/task_usage.py +28 -0
  234. arkruntime/types/content_generation/tool.py +18 -0
  235. arkruntime/types/content_generation/tool_param.py +17 -0
  236. arkruntime/types/content_generation/tool_type.py +13 -0
  237. arkruntime/types/content_generation/tool_type_param.py +11 -0
  238. arkruntime/types/content_generation/tool_usage.py +18 -0
  239. arkruntime/types/content_generation/video_role.py +16 -0
  240. arkruntime/types/content_generation/video_url.py +16 -0
  241. arkruntime/types/content_generation/video_url_param.py +14 -0
  242. arkruntime/types/embedding/__init__.py +30 -0
  243. arkruntime/types/embedding/_init_extras_shim.py +12 -0
  244. arkruntime/types/embedding/embedding.py +18 -0
  245. arkruntime/types/embedding/embedding_input.py +18 -0
  246. arkruntime/types/embedding/embedding_input_param.py +16 -0
  247. arkruntime/types/embedding/embedding_item.py +32 -0
  248. arkruntime/types/embedding/embedding_request.py +39 -0
  249. arkruntime/types/embedding/embedding_request_param.py +37 -0
  250. arkruntime/types/embedding/embedding_response.py +41 -0
  251. arkruntime/types/embedding/embedding_usage.py +24 -0
  252. arkruntime/types/embedding/encoding_format.py +14 -0
  253. arkruntime/types/environment/__init__.py +36 -0
  254. arkruntime/types/environment/_init_extras_shim.py +12 -0
  255. arkruntime/types/environment/create_environment_request.py +41 -0
  256. arkruntime/types/environment/delete_environment_response.py +24 -0
  257. arkruntime/types/environment/env_config.py +38 -0
  258. arkruntime/types/environment/env_config_type.py +18 -0
  259. arkruntime/types/environment/environment.py +57 -0
  260. arkruntime/types/environment/environment_scope.py +18 -0
  261. arkruntime/types/environment/list_environments_response.py +30 -0
  262. arkruntime/types/environment/networking_config.py +37 -0
  263. arkruntime/types/environment/networking_type.py +18 -0
  264. arkruntime/types/environment/packages_config.py +47 -0
  265. arkruntime/types/environment/update_environment_request.py +45 -0
  266. arkruntime/types/file/__init__.py +40 -0
  267. arkruntime/types/file/_init_extras_shim.py +12 -0
  268. arkruntime/types/file/file_create_request.py +41 -0
  269. arkruntime/types/file/file_create_request_param.py +41 -0
  270. arkruntime/types/file/file_deleted.py +30 -0
  271. arkruntime/types/file/file_error.py +32 -0
  272. arkruntime/types/file/file_list_response.py +42 -0
  273. arkruntime/types/file/file_object.py +71 -0
  274. arkruntime/types/file/order.py +18 -0
  275. arkruntime/types/file/preprocess_configs.py +24 -0
  276. arkruntime/types/file/preprocess_configs_param.py +22 -0
  277. arkruntime/types/file/purpose.py +18 -0
  278. arkruntime/types/file/status.py +19 -0
  279. arkruntime/types/file/tos_storage.py +28 -0
  280. arkruntime/types/file/tos_storage_param.py +25 -0
  281. arkruntime/types/file/video.py +26 -0
  282. arkruntime/types/file/video_param.py +23 -0
  283. arkruntime/types/images/__init__.py +55 -0
  284. arkruntime/types/images/_init_extras_shim.py +12 -0
  285. arkruntime/types/images/bounding_box.py +27 -0
  286. arkruntime/types/images/create_image_generation_request.py +88 -0
  287. arkruntime/types/images/create_image_generation_request_param.py +73 -0
  288. arkruntime/types/images/image_data_item.py +58 -0
  289. arkruntime/types/images/image_error.py +20 -0
  290. arkruntime/types/images/image_generation_response.py +43 -0
  291. arkruntime/types/images/image_generation_stream_event.py +74 -0
  292. arkruntime/types/images/image_generation_stream_event_type.py +19 -0
  293. arkruntime/types/images/optimize_prompt_mode.py +18 -0
  294. arkruntime/types/images/optimize_prompt_options.py +20 -0
  295. arkruntime/types/images/optimize_prompt_options_param.py +18 -0
  296. arkruntime/types/images/output_format.py +18 -0
  297. arkruntime/types/images/response_format.py +18 -0
  298. arkruntime/types/images/sequential_image_generation_mode.py +18 -0
  299. arkruntime/types/images/sequential_image_generation_options.py +18 -0
  300. arkruntime/types/images/sequential_image_generation_options_param.py +16 -0
  301. arkruntime/types/images/tool.py +18 -0
  302. arkruntime/types/images/tool_param.py +17 -0
  303. arkruntime/types/images/tool_type.py +13 -0
  304. arkruntime/types/images/tool_type_param.py +11 -0
  305. arkruntime/types/images/tool_usage.py +18 -0
  306. arkruntime/types/images/usage.py +36 -0
  307. arkruntime/types/memory/__init__.py +44 -0
  308. arkruntime/types/memory/_init_extras_shim.py +12 -0
  309. arkruntime/types/memory/actor.py +26 -0
  310. arkruntime/types/memory/actor_type.py +16 -0
  311. arkruntime/types/memory/create_memory_request.py +24 -0
  312. arkruntime/types/memory/create_memory_store_request.py +30 -0
  313. arkruntime/types/memory/delete_memory_response.py +26 -0
  314. arkruntime/types/memory/delete_memory_store_response.py +26 -0
  315. arkruntime/types/memory/list_memories_order_by.py +18 -0
  316. arkruntime/types/memory/list_memories_response.py +32 -0
  317. arkruntime/types/memory/list_memory_stores_response.py +28 -0
  318. arkruntime/types/memory/memory.py +64 -0
  319. arkruntime/types/memory/memory_list_item.py +58 -0
  320. arkruntime/types/memory/memory_list_item_type.py +20 -0
  321. arkruntime/types/memory/memory_store.py +64 -0
  322. arkruntime/types/memory/update_memory_request.py +27 -0
  323. arkruntime/types/memory/update_memory_store_request.py +31 -0
  324. arkruntime/types/multimodal_embedding/__init__.py +54 -0
  325. arkruntime/types/multimodal_embedding/_init_extras_shim.py +12 -0
  326. arkruntime/types/multimodal_embedding/embedding.py +13 -0
  327. arkruntime/types/multimodal_embedding/embedding_data_item.py +33 -0
  328. arkruntime/types/multimodal_embedding/embedding_input.py +34 -0
  329. arkruntime/types/multimodal_embedding/embedding_input_param.py +29 -0
  330. arkruntime/types/multimodal_embedding/embedding_input_type.py +15 -0
  331. arkruntime/types/multimodal_embedding/embedding_object.py +14 -0
  332. arkruntime/types/multimodal_embedding/embedding_usage.py +26 -0
  333. arkruntime/types/multimodal_embedding/encoding_format.py +14 -0
  334. arkruntime/types/multimodal_embedding/image_url.py +16 -0
  335. arkruntime/types/multimodal_embedding/image_url_param.py +14 -0
  336. arkruntime/types/multimodal_embedding/multi_embedding_config.py +18 -0
  337. arkruntime/types/multimodal_embedding/multi_embedding_config_param.py +17 -0
  338. arkruntime/types/multimodal_embedding/multi_embedding_mode.py +14 -0
  339. arkruntime/types/multimodal_embedding/multi_modal_embedding_request.py +47 -0
  340. arkruntime/types/multimodal_embedding/multi_modal_embedding_request_param.py +39 -0
  341. arkruntime/types/multimodal_embedding/multi_modal_embedding_response.py +41 -0
  342. arkruntime/types/multimodal_embedding/prompt_tokens_details.py +20 -0
  343. arkruntime/types/multimodal_embedding/sparse_embedding_config.py +20 -0
  344. arkruntime/types/multimodal_embedding/sparse_embedding_config_param.py +18 -0
  345. arkruntime/types/multimodal_embedding/sparse_embedding_mode.py +14 -0
  346. arkruntime/types/multimodal_embedding/sparse_embedding_value.py +20 -0
  347. arkruntime/types/multimodal_embedding/video_url.py +22 -0
  348. arkruntime/types/multimodal_embedding/video_url_param.py +19 -0
  349. arkruntime/types/responses/__init__.py +528 -0
  350. arkruntime/types/responses/_init_extras_shim.py +47 -0
  351. arkruntime/types/responses/annotation.py +20 -0
  352. arkruntime/types/responses/annotation_param.py +14 -0
  353. arkruntime/types/responses/applied_edit.py +22 -0
  354. arkruntime/types/responses/audio_chunk.py +15 -0
  355. arkruntime/types/responses/audio_chunking_strategy.py +18 -0
  356. arkruntime/types/responses/audio_chunking_strategy_param.py +21 -0
  357. arkruntime/types/responses/cache_mode.py +14 -0
  358. arkruntime/types/responses/clear_thinking.py +18 -0
  359. arkruntime/types/responses/clear_thinking_keep.py +18 -0
  360. arkruntime/types/responses/clear_thinking_keep_param.py +19 -0
  361. arkruntime/types/responses/clear_thinking_param.py +19 -0
  362. arkruntime/types/responses/clear_thinking_response.py +16 -0
  363. arkruntime/types/responses/clear_tool_uses.py +23 -0
  364. arkruntime/types/responses/clear_tool_uses_inputs.py +18 -0
  365. arkruntime/types/responses/clear_tool_uses_inputs_param.py +19 -0
  366. arkruntime/types/responses/clear_tool_uses_param.py +27 -0
  367. arkruntime/types/responses/clear_tool_uses_response.py +16 -0
  368. arkruntime/types/responses/content_filter.py +14 -0
  369. arkruntime/types/responses/content_item.py +36 -0
  370. arkruntime/types/responses/content_item_audio.py +20 -0
  371. arkruntime/types/responses/content_item_audio_param.py +23 -0
  372. arkruntime/types/responses/content_item_file.py +19 -0
  373. arkruntime/types/responses/content_item_file_param.py +23 -0
  374. arkruntime/types/responses/content_item_image.py +22 -0
  375. arkruntime/types/responses/content_item_image_param.py +26 -0
  376. arkruntime/types/responses/content_item_param.py +29 -0
  377. arkruntime/types/responses/content_item_text.py +22 -0
  378. arkruntime/types/responses/content_item_text_param.py +19 -0
  379. arkruntime/types/responses/content_item_video.py +27 -0
  380. arkruntime/types/responses/content_item_video_param.py +24 -0
  381. arkruntime/types/responses/context_management.py +17 -0
  382. arkruntime/types/responses/context_management_param.py +17 -0
  383. arkruntime/types/responses/context_management_response.py +17 -0
  384. arkruntime/types/responses/cover_image.py +26 -0
  385. arkruntime/types/responses/cover_image_param.py +22 -0
  386. arkruntime/types/responses/delete_response_response.py +17 -0
  387. arkruntime/types/responses/doc_citation.py +19 -0
  388. arkruntime/types/responses/doc_citation_param.py +23 -0
  389. arkruntime/types/responses/doubao_app_call_block.py +30 -0
  390. arkruntime/types/responses/doubao_app_call_block_output_text.py +21 -0
  391. arkruntime/types/responses/doubao_app_call_block_reasoning_search.py +24 -0
  392. arkruntime/types/responses/doubao_app_call_block_reasoning_text.py +21 -0
  393. arkruntime/types/responses/doubao_app_call_block_search.py +24 -0
  394. arkruntime/types/responses/doubao_app_feature.py +20 -0
  395. arkruntime/types/responses/doubao_app_feature_item.py +18 -0
  396. arkruntime/types/responses/doubao_app_feature_item_param.py +19 -0
  397. arkruntime/types/responses/doubao_app_feature_mode.py +14 -0
  398. arkruntime/types/responses/doubao_app_feature_param.py +23 -0
  399. arkruntime/types/responses/doubao_app_search_result.py +15 -0
  400. arkruntime/types/responses/doubao_app_search_text_item.py +15 -0
  401. arkruntime/types/responses/doubao_app_tool.py +20 -0
  402. arkruntime/types/responses/doubao_app_tool_param.py +22 -0
  403. arkruntime/types/responses/edit.py +19 -0
  404. arkruntime/types/responses/edit_param.py +14 -0
  405. arkruntime/types/responses/function_tool.py +32 -0
  406. arkruntime/types/responses/function_tool_param.py +29 -0
  407. arkruntime/types/responses/image_detail.py +16 -0
  408. arkruntime/types/responses/image_pixel_limit.py +16 -0
  409. arkruntime/types/responses/image_pixel_limit_param.py +17 -0
  410. arkruntime/types/responses/image_process_options.py +15 -0
  411. arkruntime/types/responses/image_process_options_param.py +15 -0
  412. arkruntime/types/responses/image_process_tool.py +21 -0
  413. arkruntime/types/responses/image_process_tool_param.py +25 -0
  414. arkruntime/types/responses/incomplete_details.py +24 -0
  415. arkruntime/types/responses/input_item.py +38 -0
  416. arkruntime/types/responses/input_item_list_params_shim.py +39 -0
  417. arkruntime/types/responses/input_item_param.py +33 -0
  418. arkruntime/types/responses/input_tokens_details.py +17 -0
  419. arkruntime/types/responses/item_agent_tool_call.py +20 -0
  420. arkruntime/types/responses/item_doubao_app_call.py +22 -0
  421. arkruntime/types/responses/item_easy_message.py +22 -0
  422. arkruntime/types/responses/item_easy_message_param.py +26 -0
  423. arkruntime/types/responses/item_function_image_process.py +24 -0
  424. arkruntime/types/responses/item_function_knowledge_search.py +21 -0
  425. arkruntime/types/responses/item_function_mcp_approval_request.py +34 -0
  426. arkruntime/types/responses/item_function_mcp_approval_request_param.py +28 -0
  427. arkruntime/types/responses/item_function_mcp_approval_response.py +34 -0
  428. arkruntime/types/responses/item_function_mcp_approval_response_param.py +28 -0
  429. arkruntime/types/responses/item_function_mcp_call.py +44 -0
  430. arkruntime/types/responses/item_function_mcp_call_param.py +38 -0
  431. arkruntime/types/responses/item_function_mcp_list_tools.py +36 -0
  432. arkruntime/types/responses/item_function_mcp_list_tools_param.py +30 -0
  433. arkruntime/types/responses/item_function_tool_call.py +37 -0
  434. arkruntime/types/responses/item_function_tool_call_output.py +22 -0
  435. arkruntime/types/responses/item_function_tool_call_output_param.py +26 -0
  436. arkruntime/types/responses/item_function_tool_call_param.py +32 -0
  437. arkruntime/types/responses/item_function_web_search.py +21 -0
  438. arkruntime/types/responses/item_input_message.py +24 -0
  439. arkruntime/types/responses/item_output_message.py +23 -0
  440. arkruntime/types/responses/item_reasoning.py +24 -0
  441. arkruntime/types/responses/item_reasoning_param.py +29 -0
  442. arkruntime/types/responses/item_reference.py +16 -0
  443. arkruntime/types/responses/item_status.py +17 -0
  444. arkruntime/types/responses/item_transcription.py +21 -0
  445. arkruntime/types/responses/knowledge_search_tool.py +46 -0
  446. arkruntime/types/responses/knowledge_search_tool_param.py +37 -0
  447. arkruntime/types/responses/list_input_items_response.py +21 -0
  448. arkruntime/types/responses/mcp_allowed_tools.py +17 -0
  449. arkruntime/types/responses/mcp_allowed_tools_filter.py +15 -0
  450. arkruntime/types/responses/mcp_allowed_tools_filter_param.py +15 -0
  451. arkruntime/types/responses/mcp_allowed_tools_param.py +13 -0
  452. arkruntime/types/responses/mcp_approval_mode.py +14 -0
  453. arkruntime/types/responses/mcp_list_tools_tool.py +30 -0
  454. arkruntime/types/responses/mcp_list_tools_tool_param.py +25 -0
  455. arkruntime/types/responses/mcp_require_approval.py +18 -0
  456. arkruntime/types/responses/mcp_require_approval_param.py +14 -0
  457. arkruntime/types/responses/mcp_tool.py +24 -0
  458. arkruntime/types/responses/mcp_tool_approval_filter.py +19 -0
  459. arkruntime/types/responses/mcp_tool_approval_filter_always.py +15 -0
  460. arkruntime/types/responses/mcp_tool_approval_filter_always_param.py +15 -0
  461. arkruntime/types/responses/mcp_tool_approval_filter_never.py +15 -0
  462. arkruntime/types/responses/mcp_tool_approval_filter_never_param.py +15 -0
  463. arkruntime/types/responses/mcp_tool_approval_filter_param.py +20 -0
  464. arkruntime/types/responses/mcp_tool_param.py +30 -0
  465. arkruntime/types/responses/message_content.py +15 -0
  466. arkruntime/types/responses/message_content_param.py +13 -0
  467. arkruntime/types/responses/message_role.py +16 -0
  468. arkruntime/types/responses/order.py +18 -0
  469. arkruntime/types/responses/output_content_item.py +23 -0
  470. arkruntime/types/responses/output_content_item_param.py +18 -0
  471. arkruntime/types/responses/output_content_item_reasoning_text.py +19 -0
  472. arkruntime/types/responses/output_content_item_reasoning_text_param.py +21 -0
  473. arkruntime/types/responses/output_content_item_text.py +19 -0
  474. arkruntime/types/responses/output_content_item_text_param.py +21 -0
  475. arkruntime/types/responses/output_item.py +46 -0
  476. arkruntime/types/responses/output_tokens_details.py +13 -0
  477. arkruntime/types/responses/parsed_response_shim.py +106 -0
  478. arkruntime/types/responses/reasoning.py +17 -0
  479. arkruntime/types/responses/reasoning_effort.py +19 -0
  480. arkruntime/types/responses/reasoning_param.py +17 -0
  481. arkruntime/types/responses/reasoning_summary_part.py +16 -0
  482. arkruntime/types/responses/reasoning_summary_part_param.py +17 -0
  483. arkruntime/types/responses/response.py +58 -0
  484. arkruntime/types/responses/response_agent_tool_call_completed_event.py +19 -0
  485. arkruntime/types/responses/response_agent_tool_call_in_progress_event.py +19 -0
  486. arkruntime/types/responses/response_caching.py +18 -0
  487. arkruntime/types/responses/response_caching_param.py +19 -0
  488. arkruntime/types/responses/response_completed_event.py +28 -0
  489. arkruntime/types/responses/response_content_part_added_event.py +22 -0
  490. arkruntime/types/responses/response_content_part_done_event.py +22 -0
  491. arkruntime/types/responses/response_created_event.py +28 -0
  492. arkruntime/types/responses/response_doubao_app_call_block_added_event.py +21 -0
  493. arkruntime/types/responses/response_doubao_app_call_block_done_event.py +21 -0
  494. arkruntime/types/responses/response_doubao_app_call_completed_event.py +22 -0
  495. arkruntime/types/responses/response_doubao_app_call_failed_event.py +19 -0
  496. arkruntime/types/responses/response_doubao_app_call_in_progress_event.py +19 -0
  497. arkruntime/types/responses/response_doubao_app_call_output_text_delta_event.py +20 -0
  498. arkruntime/types/responses/response_doubao_app_call_output_text_done_event.py +20 -0
  499. arkruntime/types/responses/response_doubao_app_call_reasoning_search_completed_event.py +24 -0
  500. arkruntime/types/responses/response_doubao_app_call_reasoning_search_in_progress_event.py +19 -0
  501. arkruntime/types/responses/response_doubao_app_call_reasoning_search_searching_event.py +20 -0
  502. arkruntime/types/responses/response_doubao_app_call_reasoning_text_delta_event.py +20 -0
  503. arkruntime/types/responses/response_doubao_app_call_reasoning_text_done_event.py +20 -0
  504. arkruntime/types/responses/response_doubao_app_call_search_completed_event.py +24 -0
  505. arkruntime/types/responses/response_doubao_app_call_search_in_progress_event.py +19 -0
  506. arkruntime/types/responses/response_doubao_app_call_search_searching_event.py +20 -0
  507. arkruntime/types/responses/response_error.py +20 -0
  508. arkruntime/types/responses/response_error_event.py +34 -0
  509. arkruntime/types/responses/response_failed_event.py +28 -0
  510. arkruntime/types/responses/response_function_call_arguments_delta_event.py +34 -0
  511. arkruntime/types/responses/response_function_call_arguments_done_event.py +31 -0
  512. arkruntime/types/responses/response_image_process_action.py +16 -0
  513. arkruntime/types/responses/response_image_process_call_completed_event.py +22 -0
  514. arkruntime/types/responses/response_image_process_call_in_progress_event.py +21 -0
  515. arkruntime/types/responses/response_image_process_call_processing_event.py +22 -0
  516. arkruntime/types/responses/response_image_process_error.py +13 -0
  517. arkruntime/types/responses/response_in_progress_event.py +28 -0
  518. arkruntime/types/responses/response_includable.py +15 -0
  519. arkruntime/types/responses/response_incomplete_event.py +28 -0
  520. arkruntime/types/responses/response_knowledge_search_call_completed_event.py +21 -0
  521. arkruntime/types/responses/response_knowledge_search_call_failed_event.py +21 -0
  522. arkruntime/types/responses/response_knowledge_search_call_in_progress_event.py +21 -0
  523. arkruntime/types/responses/response_knowledge_search_call_searching_event.py +21 -0
  524. arkruntime/types/responses/response_mcp_approval_request_event.py +20 -0
  525. arkruntime/types/responses/response_mcp_call_arguments_delta_event.py +35 -0
  526. arkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
  527. arkruntime/types/responses/response_mcp_call_completed_event.py +30 -0
  528. arkruntime/types/responses/response_mcp_call_failed_event.py +30 -0
  529. arkruntime/types/responses/response_mcp_call_in_progress_event.py +30 -0
  530. arkruntime/types/responses/response_mcp_list_tools_completed_event.py +30 -0
  531. arkruntime/types/responses/response_mcp_list_tools_failed_event.py +30 -0
  532. arkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +30 -0
  533. arkruntime/types/responses/response_output_item_added_event.py +20 -0
  534. arkruntime/types/responses/response_output_item_done_event.py +20 -0
  535. arkruntime/types/responses/response_output_text_annotation_added_event.py +46 -0
  536. arkruntime/types/responses/response_reasoning_raw_text_delta_event.py +38 -0
  537. arkruntime/types/responses/response_reasoning_raw_text_done_event.py +38 -0
  538. arkruntime/types/responses/response_reasoning_summary_part_added_event.py +22 -0
  539. arkruntime/types/responses/response_reasoning_summary_part_done_event.py +22 -0
  540. arkruntime/types/responses/response_reasoning_summary_text_delta_event.py +38 -0
  541. arkruntime/types/responses/response_reasoning_summary_text_done_event.py +38 -0
  542. arkruntime/types/responses/response_reasoning_text_delta_event.py +38 -0
  543. arkruntime/types/responses/response_reasoning_text_done_event.py +38 -0
  544. arkruntime/types/responses/response_status.py +16 -0
  545. arkruntime/types/responses/response_stream_event.py +216 -0
  546. arkruntime/types/responses/response_text_config.py +15 -0
  547. arkruntime/types/responses/response_text_config_param.py +16 -0
  548. arkruntime/types/responses/response_text_delta_event.py +38 -0
  549. arkruntime/types/responses/response_text_done_event.py +38 -0
  550. arkruntime/types/responses/response_transcription_part_added_event.py +22 -0
  551. arkruntime/types/responses/response_transcription_part_done_event.py +22 -0
  552. arkruntime/types/responses/response_transcription_text_delta_event.py +46 -0
  553. arkruntime/types/responses/response_transcription_text_done_event.py +52 -0
  554. arkruntime/types/responses/response_usage.py +47 -0
  555. arkruntime/types/responses/response_web_search_call_completed_event.py +30 -0
  556. arkruntime/types/responses/response_web_search_call_in_progress_event.py +30 -0
  557. arkruntime/types/responses/response_web_search_call_searching_event.py +30 -0
  558. arkruntime/types/responses/responses_input.py +15 -0
  559. arkruntime/types/responses/responses_input_param.py +13 -0
  560. arkruntime/types/responses/responses_request.py +50 -0
  561. arkruntime/types/responses/responses_request_param.py +73 -0
  562. arkruntime/types/responses/service_tier.py +14 -0
  563. arkruntime/types/responses/session.py +13 -0
  564. arkruntime/types/responses/session_param.py +13 -0
  565. arkruntime/types/responses/text_format.py +22 -0
  566. arkruntime/types/responses/text_format_param.py +25 -0
  567. arkruntime/types/responses/text_format_type.py +15 -0
  568. arkruntime/types/responses/text_translation_options.py +14 -0
  569. arkruntime/types/responses/thinking.py +17 -0
  570. arkruntime/types/responses/thinking_mode.py +15 -0
  571. arkruntime/types/responses/thinking_param.py +17 -0
  572. arkruntime/types/responses/thinking_turns_param.py +16 -0
  573. arkruntime/types/responses/thinking_turns_param_param.py +17 -0
  574. arkruntime/types/responses/tool.py +34 -0
  575. arkruntime/types/responses/tool_choice.py +16 -0
  576. arkruntime/types/responses/tool_choice_function.py +22 -0
  577. arkruntime/types/responses/tool_choice_function_param.py +19 -0
  578. arkruntime/types/responses/tool_choice_knowledge_search.py +15 -0
  579. arkruntime/types/responses/tool_choice_knowledge_search_param.py +15 -0
  580. arkruntime/types/responses/tool_choice_mcp.py +26 -0
  581. arkruntime/types/responses/tool_choice_mcp_param.py +22 -0
  582. arkruntime/types/responses/tool_choice_options.py +15 -0
  583. arkruntime/types/responses/tool_choice_param.py +14 -0
  584. arkruntime/types/responses/tool_choice_web_search.py +15 -0
  585. arkruntime/types/responses/tool_choice_web_search_param.py +15 -0
  586. arkruntime/types/responses/tool_name_list.py +15 -0
  587. arkruntime/types/responses/tool_name_list_param.py +15 -0
  588. arkruntime/types/responses/tool_param.py +25 -0
  589. arkruntime/types/responses/tool_usage.py +27 -0
  590. arkruntime/types/responses/tool_usage_details.py +30 -0
  591. arkruntime/types/responses/tool_uses_keep.py +16 -0
  592. arkruntime/types/responses/tool_uses_keep_param.py +17 -0
  593. arkruntime/types/responses/tool_uses_trigger.py +16 -0
  594. arkruntime/types/responses/tool_uses_trigger_param.py +17 -0
  595. arkruntime/types/responses/transcription_part.py +19 -0
  596. arkruntime/types/responses/truncation_mode.py +14 -0
  597. arkruntime/types/responses/typed_tool_choice.py +30 -0
  598. arkruntime/types/responses/typed_tool_choice_param.py +21 -0
  599. arkruntime/types/responses/url_citation.py +26 -0
  600. arkruntime/types/responses/url_citation_param.py +35 -0
  601. arkruntime/types/responses/user_location.py +34 -0
  602. arkruntime/types/responses/user_location_param.py +28 -0
  603. arkruntime/types/responses/web_search_action.py +16 -0
  604. arkruntime/types/responses/web_search_source.py +16 -0
  605. arkruntime/types/responses/web_search_tool.py +22 -0
  606. arkruntime/types/responses/web_search_tool_param.py +26 -0
  607. arkruntime/types/session/__init__.py +154 -0
  608. arkruntime/types/session/_init_extras_shim.py +88 -0
  609. arkruntime/types/session/agent_identifier.py +19 -0
  610. arkruntime/types/session/agent_ref.py +31 -0
  611. arkruntime/types/session/base64_document_source.py +27 -0
  612. arkruntime/types/session/base64_image_source.py +27 -0
  613. arkruntime/types/session/cache_creation.py +26 -0
  614. arkruntime/types/session/create_session_request.py +50 -0
  615. arkruntime/types/session/create_session_resource_request.py +29 -0
  616. arkruntime/types/session/delete_session_response.py +24 -0
  617. arkruntime/types/session/document_source.py +34 -0
  618. arkruntime/types/session/file_document_source.py +23 -0
  619. arkruntime/types/session/file_image_source.py +23 -0
  620. arkruntime/types/session/image_source.py +28 -0
  621. arkruntime/types/session/list_session_events_response_wire.py +31 -0
  622. arkruntime/types/session/list_session_resources_response.py +24 -0
  623. arkruntime/types/session/list_session_threads_response.py +28 -0
  624. arkruntime/types/session/list_sessions_order.py +18 -0
  625. arkruntime/types/session/list_sessions_response.py +28 -0
  626. arkruntime/types/session/managed_agents_agent_message_preview.py +27 -0
  627. arkruntime/types/session/managed_agents_agent_thinking_preview.py +27 -0
  628. arkruntime/types/session/managed_agents_delta_content.py +34 -0
  629. arkruntime/types/session/managed_agents_delta_event.py +34 -0
  630. arkruntime/types/session/managed_agents_delta_text_block.py +27 -0
  631. arkruntime/types/session/managed_agents_document_block.py +33 -0
  632. arkruntime/types/session/managed_agents_event_params.py +57 -0
  633. arkruntime/types/session/managed_agents_file_rubric_params.py +23 -0
  634. arkruntime/types/session/managed_agents_image_block.py +25 -0
  635. arkruntime/types/session/managed_agents_message_content_block.py +30 -0
  636. arkruntime/types/session/managed_agents_rubric.py +26 -0
  637. arkruntime/types/session/managed_agents_search_result_block.py +38 -0
  638. arkruntime/types/session/managed_agents_session_event.py +34 -0
  639. arkruntime/types/session/managed_agents_start_event.py +31 -0
  640. arkruntime/types/session/managed_agents_start_event_preview.py +27 -0
  641. arkruntime/types/session/managed_agents_stream_preview_event.py +26 -0
  642. arkruntime/types/session/managed_agents_system_content_block.py +23 -0
  643. arkruntime/types/session/managed_agents_system_message_event_params.py +34 -0
  644. arkruntime/types/session/managed_agents_text_block.py +23 -0
  645. arkruntime/types/session/managed_agents_text_rubric_params.py +23 -0
  646. arkruntime/types/session/managed_agents_tool_result_content_block.py +34 -0
  647. arkruntime/types/session/managed_agents_user_custom_tool_result_event_params.py +44 -0
  648. arkruntime/types/session/managed_agents_user_define_outcome_event_params.py +45 -0
  649. arkruntime/types/session/managed_agents_user_interrupt_event_params.py +31 -0
  650. arkruntime/types/session/managed_agents_user_message_event_params.py +34 -0
  651. arkruntime/types/session/managed_agents_user_tool_confirmation_event_params.py +46 -0
  652. arkruntime/types/session/managed_agents_user_tool_result_event_params.py +44 -0
  653. arkruntime/types/session/plain_text_document_source.py +27 -0
  654. arkruntime/types/session/search_result_citations.py +20 -0
  655. arkruntime/types/session/search_result_content.py +20 -0
  656. arkruntime/types/session/send_session_events_request.py +24 -0
  657. arkruntime/types/session/send_session_events_response.py +22 -0
  658. arkruntime/types/session/session.py +80 -0
  659. arkruntime/types/session/session_resource.py +70 -0
  660. arkruntime/types/session/session_resource_access.py +18 -0
  661. arkruntime/types/session/session_resource_type.py +19 -0
  662. arkruntime/types/session/session_status.py +20 -0
  663. arkruntime/types/session/session_stream_shim.py +540 -0
  664. arkruntime/types/session/session_thread.py +56 -0
  665. arkruntime/types/session/session_thread_status.py +20 -0
  666. arkruntime/types/session/session_usage.py +36 -0
  667. arkruntime/types/session/tag.py +26 -0
  668. arkruntime/types/session/tool_confirmation_result.py +18 -0
  669. arkruntime/types/session/update_session_request.py +28 -0
  670. arkruntime/types/session/url_document_source.py +23 -0
  671. arkruntime/types/session/url_image_source.py +23 -0
  672. arkruntime/types/skill/__init__.py +18 -0
  673. arkruntime/types/skill/_init_extras_shim.py +12 -0
  674. arkruntime/types/skill/create_skill_request.py +18 -0
  675. arkruntime/types/skill/skill.py +46 -0
  676. arkruntime/types/tokenization/__init__.py +24 -0
  677. arkruntime/types/tokenization/_init_extras_shim.py +12 -0
  678. arkruntime/types/tokenization/tokenization_input.py +17 -0
  679. arkruntime/types/tokenization/tokenization_input_param.py +15 -0
  680. arkruntime/types/tokenization/tokenization_item.py +39 -0
  681. arkruntime/types/tokenization/tokenization_request.py +30 -0
  682. arkruntime/types/tokenization/tokenization_request_param.py +30 -0
  683. arkruntime/types/tokenization/tokenization_response.py +36 -0
  684. arkruntime/types/vault/__init__.py +62 -0
  685. arkruntime/types/vault/_init_extras_shim.py +12 -0
  686. arkruntime/types/vault/create_credential_request.py +32 -0
  687. arkruntime/types/vault/create_vault_request.py +26 -0
  688. arkruntime/types/vault/credential.py +52 -0
  689. arkruntime/types/vault/credential_auth.py +64 -0
  690. arkruntime/types/vault/credential_auth_type.py +22 -0
  691. arkruntime/types/vault/credential_networking.py +29 -0
  692. arkruntime/types/vault/credential_networking_type.py +18 -0
  693. arkruntime/types/vault/credential_validation.py +54 -0
  694. arkruntime/types/vault/delete_credential_response.py +26 -0
  695. arkruntime/types/vault/delete_vault_response.py +26 -0
  696. arkruntime/types/vault/limited_credential_networking.py +22 -0
  697. arkruntime/types/vault/list_credentials_response.py +35 -0
  698. arkruntime/types/vault/list_vaults_response.py +32 -0
  699. arkruntime/types/vault/mcp_probe.py +26 -0
  700. arkruntime/types/vault/mcpo_auth_refresh.py +45 -0
  701. arkruntime/types/vault/refresh_http_response.py +32 -0
  702. arkruntime/types/vault/refresh_object.py +27 -0
  703. arkruntime/types/vault/refresh_status.py +20 -0
  704. arkruntime/types/vault/token_endpoint_auth.py +29 -0
  705. arkruntime/types/vault/token_endpoint_auth_type.py +19 -0
  706. arkruntime/types/vault/update_credential_request.py +35 -0
  707. arkruntime/types/vault/update_vault_request.py +27 -0
  708. arkruntime/types/vault/validation_status.py +19 -0
  709. arkruntime/types/vault/vault.py +42 -0
  710. arkruntime-0.1.0.dist-info/METADATA +347 -0
  711. arkruntime-0.1.0.dist-info/RECORD +714 -0
  712. arkruntime-0.1.0.dist-info/WHEEL +5 -0
  713. arkruntime-0.1.0.dist-info/licenses/LICENSE +201 -0
  714. arkruntime-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1373 @@
1
+ # Copyright (c) 2025 ByteDance Ltd. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # License text: https://github.com/volcengine/ark-runtime-python/blob/main/LICENSE
4
+
5
+ from __future__ import annotations
6
+
7
+ import asyncio
8
+ import json
9
+ import logging
10
+ import time
11
+ from random import random
12
+ from types import TracebackType
13
+ from typing import (
14
+ TYPE_CHECKING,
15
+ Any,
16
+ AsyncIterator,
17
+ Dict,
18
+ Generator,
19
+ Generic,
20
+ Iterable,
21
+ Iterator,
22
+ Mapping,
23
+ Optional,
24
+ Type,
25
+ TypeVar,
26
+ Union,
27
+ cast,
28
+ )
29
+
30
+ import anyio
31
+ import httpx
32
+ import pydantic
33
+ from httpx import URL, Limits, Timeout
34
+ from httpx._types import RequestFiles
35
+ from pydantic import PrivateAttr
36
+ from typing_extensions import override
37
+
38
+ from . import _exceptions # type: ignore
39
+ from ._compat import PYDANTIC_V2, model_copy, model_dump
40
+ from ._constants import (
41
+ CLIENT_REQUEST_HEADER,
42
+ DEFAULT_CONNECTION_LIMITS,
43
+ DEFAULT_MAX_RETRIES,
44
+ DEFAULT_TIMEOUT,
45
+ INITIAL_RETRY_DELAY,
46
+ MAX_RETRY_DELAY,
47
+ RAW_RESPONSE_HEADER,
48
+ VERSION,
49
+ )
50
+ from ._exceptions import (
51
+ ArkAPIConnectionError,
52
+ ArkAPIResponseValidationError,
53
+ ArkAPIStatusError,
54
+ ArkAPITimeoutError,
55
+ )
56
+ from ._files import async_to_httpx_files, to_httpx_files
57
+ from ._models import GenericModel, construct_type
58
+ from ._qs import Querystring
59
+ from ._request_options import ExtraRequestOptions, RequestOptions
60
+ from ._response import ArkAPIResponse, ArkAsyncAPIResponse
61
+ from ._streaming import AsyncStream, SSEBytesDecoder, SSEDecoder, Stream
62
+ from ._types import (
63
+ NOT_GIVEN,
64
+ Body,
65
+ HttpxRequestFiles,
66
+ NotGiven,
67
+ PostParser,
68
+ Query,
69
+ ResponseT,
70
+ )
71
+ from ._utils._utils import _gen_request_id, is_dict, is_given, is_list, is_mapping
72
+
73
+ SyncPageT = TypeVar("SyncPageT", bound="BaseSyncPage[Any]")
74
+ AsyncPageT = TypeVar("AsyncPageT", bound="BaseAsyncPage[Any]")
75
+
76
+ _T = TypeVar("_T")
77
+ _T_co = TypeVar("_T_co", covariant=True)
78
+
79
+ _StreamT = TypeVar("_StreamT", bound=Stream[Any])
80
+ _AsyncStreamT = TypeVar("_AsyncStreamT", bound=AsyncStream[Any])
81
+
82
+ log: logging.Logger = logging.getLogger(__name__)
83
+
84
+
85
+ class _DefaultHttpxClient(httpx.Client):
86
+ def __init__(self, **kwargs: Any) -> None:
87
+ kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
88
+ kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
89
+ kwargs.setdefault("follow_redirects", True)
90
+ super().__init__(**kwargs)
91
+
92
+
93
+ if TYPE_CHECKING:
94
+ DefaultHttpxClient = httpx.Client
95
+ """An alias to `httpx.Client` that provides the same defaults that this SDK
96
+ uses internally.
97
+
98
+ This is useful because overriding the `http_client` with your own instance of
99
+ `httpx.Client` will result in httpx's defaults being used, not ours.
100
+ """
101
+ else:
102
+ DefaultHttpxClient = _DefaultHttpxClient
103
+
104
+
105
+ class SyncHttpxClientWrapper(DefaultHttpxClient):
106
+ def __del__(self) -> None:
107
+ try:
108
+ self.close()
109
+ except Exception:
110
+ pass
111
+
112
+
113
+ def make_request_options(
114
+ *,
115
+ query: Dict[str, Any] | None = None,
116
+ extra_headers: Dict[str, str] | None = None,
117
+ extra_query: Dict[str, Any] | None = None,
118
+ extra_body: Dict[str, Any] | None = None,
119
+ timeout: float | httpx.Timeout | None = None,
120
+ post_parser: PostParser | NotGiven = NOT_GIVEN,
121
+ ) -> ExtraRequestOptions:
122
+ options: ExtraRequestOptions = {}
123
+ if extra_headers is not None:
124
+ options["headers"] = extra_headers
125
+
126
+ if extra_body is not None:
127
+ options["extra_body"] = extra_body
128
+
129
+ if query is not None:
130
+ options["params"] = query
131
+
132
+ if extra_query is not None:
133
+ options["params"] = {**options.get("params", {}), **extra_query}
134
+
135
+ if timeout:
136
+ options["timeout"] = timeout
137
+
138
+ if is_given(post_parser):
139
+ # internal
140
+ options["post_parser"] = post_parser # type: ignore
141
+
142
+ return options
143
+
144
+
145
+ _HttpxClientT = TypeVar("_HttpxClientT", bound=Union[httpx.Client, httpx.AsyncClient])
146
+
147
+
148
+ class BaseClient(Generic[_HttpxClientT]):
149
+ _client: _HttpxClientT
150
+ _base_url: URL
151
+ max_retries: int
152
+ timeout: Union[float, Timeout, None]
153
+ _limits: Union[httpx.Limits, None]
154
+
155
+ def __init__(
156
+ self,
157
+ *,
158
+ base_url: str | URL,
159
+ max_retries: int = DEFAULT_MAX_RETRIES,
160
+ timeout: float | Timeout | None = DEFAULT_TIMEOUT,
161
+ limits: Limits | None = None,
162
+ custom_headers: Dict[str, str] | None = None,
163
+ custom_query: Dict[str, Any] | None = None,
164
+ ) -> None:
165
+ self._base_url = self._enforce_trailing_slash(URL(base_url))
166
+ self.max_retries = max_retries
167
+ self.timeout = timeout
168
+ self._limits = limits
169
+ self._custom_headers = custom_headers or {}
170
+ self._custom_query = custom_query or {}
171
+
172
+ if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
173
+ raise TypeError(
174
+ "max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number`"
175
+ )
176
+
177
+ @property
178
+ def qs(self) -> Querystring:
179
+ return Querystring()
180
+
181
+ @property
182
+ def auth_headers(self) -> dict[str, str]:
183
+ return {}
184
+
185
+ @property
186
+ def user_agent(self) -> str:
187
+ return "volc-sdk-python/" + VERSION
188
+
189
+ def default_headers(self) -> Dict[str, str]:
190
+ return {
191
+ "Accept": "application/json",
192
+ "Content-Type": "application/json",
193
+ "User-Agent": self.user_agent,
194
+ CLIENT_REQUEST_HEADER: _gen_request_id(),
195
+ **self.auth_headers,
196
+ **self._custom_headers,
197
+ }
198
+
199
+ def _make_sse_decoder(self) -> SSEDecoder | SSEBytesDecoder:
200
+ return SSEDecoder()
201
+
202
+ def _build_headers(self, options: RequestOptions) -> httpx.Headers:
203
+ custom_headers = options.headers or {}
204
+ headers_dict = {**self.default_headers(), **custom_headers}
205
+ headers = httpx.Headers(headers_dict)
206
+
207
+ return headers
208
+
209
+ def _prepare_url(self, url: str) -> URL:
210
+ merge_url = URL(url)
211
+ if merge_url.is_relative_url:
212
+ merge_raw_path = self._base_url.raw_path + merge_url.raw_path.lstrip(b"/")
213
+ return self._base_url.copy_with(raw_path=merge_raw_path)
214
+
215
+ return merge_url
216
+
217
+ def _should_stream_response_body(self, request: httpx.Request) -> bool:
218
+ return request.headers.get(RAW_RESPONSE_HEADER) == "stream"
219
+
220
+ def _build_request(
221
+ self,
222
+ options: RequestOptions,
223
+ *,
224
+ retries_taken: int = 0,
225
+ ) -> httpx.Request:
226
+ if log.isEnabledFor(logging.DEBUG):
227
+ log.debug("Request options: %s", model_dump(options, exclude_unset=True))
228
+
229
+ kwargs: dict[str, Any] = {}
230
+
231
+ body = options.body
232
+ if options.extra_body is not None:
233
+ if body is None:
234
+ body = options.extra_body
235
+ elif isinstance(body, Dict):
236
+ body = {**body, **options.extra_body}
237
+ else:
238
+ raise RuntimeError(f"Unexpected JSON data type, {type(body)}, cannot merge with `extra_body`")
239
+
240
+ headers = self._build_headers(options)
241
+ params = options.params
242
+ content_type = headers.get("Content-Type")
243
+ files = options.files
244
+
245
+ # If the given Content-Type header is multipart/form-data then it
246
+ # has to be removed so that httpx can generate the header with
247
+ # additional information for us as it has to be in this form
248
+ # for the server to be able to correctly parse the request:
249
+ # multipart/form-data; boundary=---abc--
250
+ if content_type is not None and content_type.startswith("multipart/form-data"):
251
+ if "boundary" not in content_type:
252
+ # only remove the header if the boundary hasn't been explicitly set
253
+ # as the caller doesn't want httpx to come up with their own boundary
254
+ headers.pop("Content-Type")
255
+
256
+ # As we are now sending multipart/form-data instead of application/json
257
+ # we need to tell httpx to use it, https://www.python-httpx.org/advanced/clients/#multipart-file-encoding
258
+ if body:
259
+ if not is_dict(body):
260
+ raise TypeError(
261
+ f"Expected query input to be a dictionary for multipart requests but got {type(body)} instead."
262
+ )
263
+ kwargs["data"] = self._serialize_multipartform(body)
264
+
265
+ # httpx determines whether or not to send a "multipart/form-data"
266
+ # request based on the truthiness of the "files" argument.
267
+ # This gets around that issue by generating a dict value that
268
+ # evaluates to true.
269
+ #
270
+ # https://github.com/encode/httpx/discussions/2399#discussioncomment-3814186
271
+ if not files:
272
+ files = cast(HttpxRequestFiles, ForceMultipartDict())
273
+
274
+ prepared_url = self._prepare_url(options.url)
275
+ if "_" in prepared_url.host:
276
+ # work around https://github.com/encode/httpx/discussions/2880
277
+ kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
278
+
279
+ is_body_allowed = options.method.lower() != "get"
280
+
281
+ if is_body_allowed:
282
+ if isinstance(body, bytes):
283
+ kwargs["content"] = body
284
+ else:
285
+ kwargs["json"] = body if is_given(body) else None
286
+ kwargs["files"] = files
287
+ else:
288
+ headers.pop("Content-Type", None)
289
+ kwargs.pop("data", None)
290
+
291
+ # TODO: report this error to httpx
292
+ return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
293
+ headers=headers,
294
+ timeout=self.timeout if isinstance(options.timeout, NotGiven) else options.timeout,
295
+ method=options.method,
296
+ url=prepared_url,
297
+ # the `Query` type that we use is incompatible with qs'
298
+ # `Params` type as it needs to be typed as `Mapping[str, object]`
299
+ # so that passing a `TypedDict` doesn't cause an error.
300
+ # https://github.com/microsoft/pyright/issues/3526#event-6715453066
301
+ params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
302
+ **kwargs,
303
+ )
304
+
305
+ def _serialize_multipartform(self, data: Mapping[object, object]) -> dict[str, object]:
306
+ items = self.qs.stringify_items(
307
+ # TODO: type ignore is required as stringify_items is well typed but we can't be
308
+ # well typed without heavy validation.
309
+ data, # type: ignore
310
+ array_format="brackets",
311
+ )
312
+ serialized: dict[str, object] = {}
313
+ for key, value in items:
314
+ existing = serialized.get(key)
315
+
316
+ if not existing:
317
+ serialized[key] = value
318
+ continue
319
+
320
+ # If a value has already been set for this key then that
321
+ # means we're sending data like `array[]=[1, 2, 3]` and we
322
+ # need to tell httpx that we want to send multiple values with
323
+ # the same key which is done by using a list or a tuple.
324
+ #
325
+ # Note: 2d arrays should never result in the same key at both
326
+ # levels so it's safe to assume that if the value is a list,
327
+ # it was because we changed it to be a list.
328
+ if is_list(existing):
329
+ existing.append(value)
330
+ else:
331
+ serialized[key] = [existing, value]
332
+
333
+ return serialized
334
+
335
+ def _calculate_retry_timeout(
336
+ self,
337
+ remaining_retries: int,
338
+ options: RequestOptions,
339
+ response_headers: Optional[httpx.Headers] = None,
340
+ ) -> float:
341
+ max_retries = options.max_retries if options.max_retries else self.max_retries
342
+
343
+ nb_retries = max_retries - remaining_retries
344
+
345
+ # Apply exponential backoff, but not more than the max.
346
+ sleep_seconds = min(INITIAL_RETRY_DELAY * pow(2.0, nb_retries), MAX_RETRY_DELAY)
347
+
348
+ # Apply some jitter, plus-or-minus half a second.
349
+ jitter = 1 - 0.25 * random()
350
+ timeout = sleep_seconds * jitter
351
+ return timeout if timeout >= 0 else 0
352
+
353
+ def _should_retry(self, response: httpx.Response) -> bool:
354
+ # Note: this is not a standard header
355
+ should_retry_header = response.headers.get("x-should-retry")
356
+
357
+ # If the server explicitly says whether or not to retry, obey.
358
+ if should_retry_header == "true":
359
+ log.debug("Retrying as header `x-should-retry` is set to `true`")
360
+ return True
361
+ if should_retry_header == "false":
362
+ log.debug("Not retrying as header `x-should-retry` is set to `false`")
363
+ return False
364
+
365
+ # Retry on request timeouts.
366
+ if response.status_code == 408:
367
+ log.debug("Retrying due to status code %i", response.status_code)
368
+ return True
369
+
370
+ # Retry on lock timeouts.
371
+ if response.status_code == 409:
372
+ log.debug("Retrying due to status code %i", response.status_code)
373
+ return True
374
+
375
+ # Retry on rate limits.
376
+ if response.status_code == 429:
377
+ log.debug("Retrying due to status code %i", response.status_code)
378
+ return True
379
+
380
+ # Retry internal errors.
381
+ if response.status_code >= 500:
382
+ log.debug("Retrying due to status code %i", response.status_code)
383
+ return True
384
+
385
+ log.debug("Not retrying")
386
+ return False
387
+
388
+ def _make_status_error(
389
+ self, err_msg: str, *, body: object, response: httpx.Response, request_id: str
390
+ ) -> ArkAPIStatusError:
391
+ data = body.get("error", body) if isinstance(body, Dict) else body
392
+ if response.status_code == 400:
393
+ return _exceptions.ArkBadRequestError(err_msg, response=response, body=data, request_id=request_id)
394
+
395
+ if response.status_code == 401:
396
+ return _exceptions.ArkAuthenticationError(err_msg, response=response, body=data, request_id=request_id)
397
+
398
+ if response.status_code == 403:
399
+ return _exceptions.ArkPermissionDeniedError(err_msg, response=response, body=data, request_id=request_id)
400
+
401
+ if response.status_code == 404:
402
+ return _exceptions.ArkNotFoundError(err_msg, response=response, body=data, request_id=request_id)
403
+
404
+ if response.status_code == 409:
405
+ return _exceptions.ArkConflictError(err_msg, response=response, body=data, request_id=request_id)
406
+
407
+ if response.status_code == 422:
408
+ return _exceptions.ArkUnprocessableEntityError(err_msg, response=response, body=data, request_id=request_id)
409
+
410
+ if response.status_code == 429:
411
+ return _exceptions.ArkRateLimitError(err_msg, response=response, body=data, request_id=request_id)
412
+
413
+ if response.status_code >= 500:
414
+ return _exceptions.ArkInternalServerError(err_msg, response=response, body=data, request_id=request_id)
415
+ return ArkAPIStatusError(err_msg, response=response, body=data, request_id=request_id)
416
+
417
+ def _make_status_error_from_response(self, response: httpx.Response, request_id: str) -> ArkAPIStatusError:
418
+ if response.is_closed and not response.is_stream_consumed:
419
+ body = None
420
+ err_msg = f"Error code: {response.status_code}"
421
+ else:
422
+ err_text = response.text.strip()
423
+ body = err_text
424
+
425
+ try:
426
+ body = json.loads(err_text)
427
+ err_msg = f"Error code: {response.status_code} - {body}"
428
+ except Exception:
429
+ err_msg = err_text or f"Error code: {response.status_code}"
430
+
431
+ return self._make_status_error(err_msg, body=body, response=response, request_id=request_id)
432
+
433
+ def _enforce_trailing_slash(self, url: URL) -> URL:
434
+ if url.raw_path.endswith(b"/"):
435
+ return url
436
+ return url.copy_with(raw_path=url.raw_path + b"/")
437
+
438
+ def _process_response_data(
439
+ self,
440
+ *,
441
+ data: object,
442
+ cast_to: type[ResponseT],
443
+ response: httpx.Response,
444
+ ) -> ResponseT:
445
+ request_id = response.headers.get(CLIENT_REQUEST_HEADER, "") if response else None
446
+ if data is None:
447
+ return cast(ResponseT, None)
448
+
449
+ if cast_to is object:
450
+ return cast(ResponseT, data)
451
+
452
+ try:
453
+ return cast(ResponseT, construct_type(type_=cast_to, value=data))
454
+ except pydantic.ValidationError as err:
455
+ raise ArkAPIResponseValidationError(response=response, body=data, request_id=request_id) from err
456
+
457
+ def _remaining_retries(
458
+ self,
459
+ remaining_retries: Optional[int],
460
+ options: RequestOptions,
461
+ ) -> int:
462
+ return remaining_retries if remaining_retries is not None else options.get_max_retries(self.max_retries)
463
+
464
+
465
+ class SyncAPIClient(BaseClient):
466
+ _client: httpx.Client
467
+
468
+ def __init__(
469
+ self,
470
+ *,
471
+ base_url: str | URL,
472
+ max_retries: int = DEFAULT_MAX_RETRIES,
473
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
474
+ http_client: httpx.Client | None = None,
475
+ custom_headers: Dict[str, str] | None = None,
476
+ custom_query: Dict[str, object] | None = None,
477
+ ) -> None:
478
+ if http_client is not None and not isinstance(http_client, httpx.Client): # pyright: ignore[reportUnnecessaryIsInstance]
479
+ raise TypeError(
480
+ f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got {type(http_client)}"
481
+ )
482
+
483
+ super().__init__(
484
+ base_url=base_url,
485
+ timeout=cast(Timeout, timeout),
486
+ max_retries=max_retries,
487
+ custom_query=custom_query,
488
+ custom_headers=custom_headers,
489
+ )
490
+
491
+ self._client = http_client or SyncHttpxClientWrapper(
492
+ base_url=self._enforce_trailing_slash(URL(base_url)),
493
+ timeout=cast(Timeout, timeout),
494
+ )
495
+
496
+ def _request(
497
+ self,
498
+ *,
499
+ cast_to: Type[ResponseT],
500
+ options: RequestOptions,
501
+ remaining_retries: int | None,
502
+ stream: bool,
503
+ stream_cls: type[_StreamT] | None,
504
+ ) -> ResponseT | _StreamT:
505
+ retries = self._remaining_retries(remaining_retries, options)
506
+ request = self._build_request(options)
507
+ req_id = request.headers.get(CLIENT_REQUEST_HEADER, "")
508
+ try:
509
+ response = self._client.send(
510
+ request,
511
+ stream=stream or self._should_stream_response_body(request=request),
512
+ )
513
+ except httpx.TimeoutException as err:
514
+ if retries > 0:
515
+ return self._retry_request(
516
+ options,
517
+ cast_to,
518
+ retries,
519
+ stream=stream,
520
+ stream_cls=stream_cls,
521
+ response_headers=None,
522
+ )
523
+
524
+ log.debug("Raising timeout error")
525
+ raise ArkAPITimeoutError(request=request, request_id=req_id) from err
526
+ except Exception as err:
527
+ log.debug("Encountered Exception", exc_info=True)
528
+
529
+ if retries > 0:
530
+ return self._retry_request(
531
+ options,
532
+ cast_to,
533
+ retries,
534
+ stream=stream,
535
+ stream_cls=stream_cls,
536
+ response_headers=None,
537
+ )
538
+
539
+ log.debug("Raising connection error")
540
+ raise ArkAPIConnectionError(request=request, request_id=req_id) from err
541
+
542
+ log.debug(
543
+ 'HTTP Request: %s %s "%i %s"',
544
+ request.method,
545
+ request.url,
546
+ response.status_code,
547
+ response.reason_phrase,
548
+ )
549
+
550
+ try:
551
+ response.raise_for_status()
552
+ except httpx.HTTPStatusError as err: # thrown on 4xx and 5xx status code
553
+ log.debug("Encountered httpx.HTTPStatusError", exc_info=True)
554
+
555
+ if retries > 0 and self._should_retry(err.response):
556
+ err.response.close()
557
+ return self._retry_request(
558
+ options,
559
+ cast_to,
560
+ retries,
561
+ err.response.headers,
562
+ stream=stream,
563
+ stream_cls=stream_cls,
564
+ )
565
+
566
+ # If the response is streamed then we need to explicitly read the response
567
+ # to completion before attempting to access the response text.
568
+ if not err.response.is_closed:
569
+ err.response.read()
570
+
571
+ log.debug("Re-raising status error")
572
+ raise self._make_status_error_from_response(err.response, request_id=req_id) from None
573
+
574
+ return self._process_response(
575
+ cast_to=cast_to,
576
+ response=response,
577
+ stream=stream,
578
+ stream_cls=stream_cls,
579
+ options=options,
580
+ )
581
+
582
+ def _retry_request(
583
+ self,
584
+ options: RequestOptions,
585
+ cast_to: Type[ResponseT],
586
+ remaining_retries: int,
587
+ response_headers: httpx.Headers | None,
588
+ *,
589
+ stream: bool,
590
+ stream_cls: type[_StreamT] | None,
591
+ ) -> ResponseT | _StreamT:
592
+ remaining = remaining_retries - 1
593
+ if remaining == 1:
594
+ log.info("1 retry left")
595
+ else:
596
+ log.info("%i retries left", remaining)
597
+
598
+ timeout = self._calculate_retry_timeout(remaining, options, response_headers)
599
+ log.info("Retrying request to %s in %f seconds", options.url, timeout)
600
+
601
+ # In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a
602
+ # different thread if necessary.
603
+ time.sleep(timeout)
604
+
605
+ return self._request(
606
+ options=options,
607
+ cast_to=cast_to,
608
+ remaining_retries=remaining,
609
+ stream=stream,
610
+ stream_cls=stream_cls,
611
+ )
612
+
613
+ def _process_response(
614
+ self,
615
+ *,
616
+ cast_to: Type[ResponseT],
617
+ options: RequestOptions,
618
+ response: httpx.Response,
619
+ stream: bool,
620
+ stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None,
621
+ ) -> ResponseT:
622
+ if cast_to == httpx.Response:
623
+ return cast(ResponseT, response)
624
+
625
+ api_response = ArkAPIResponse(
626
+ raw=response,
627
+ client=self,
628
+ cast_to=cast("type[ResponseT]", cast_to), # pyright: ignore[reportUnnecessaryCast]
629
+ stream=stream,
630
+ stream_cls=stream_cls,
631
+ options=options,
632
+ )
633
+ if bool(response.request.headers.get(RAW_RESPONSE_HEADER)):
634
+ return cast(ResponseT, api_response)
635
+
636
+ return api_response.parse()
637
+
638
+ def post(
639
+ self,
640
+ path: str,
641
+ *,
642
+ cast_to: Type[ResponseT],
643
+ body: Dict | None = None,
644
+ options: ExtraRequestOptions = {},
645
+ files: RequestFiles | None = None,
646
+ stream: bool = False,
647
+ stream_cls: type[_StreamT] | None = None,
648
+ ) -> ResponseT | _StreamT:
649
+ opts = RequestOptions.construct( # type: ignore
650
+ method="post",
651
+ url=path,
652
+ files=to_httpx_files(files),
653
+ body=body,
654
+ **options,
655
+ )
656
+
657
+ return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
658
+
659
+ def get(
660
+ self,
661
+ path: str,
662
+ *,
663
+ cast_to: Type[ResponseT],
664
+ options: ExtraRequestOptions = {},
665
+ stream: bool = False,
666
+ stream_cls: type[_StreamT] | None = None,
667
+ ) -> ResponseT | _StreamT:
668
+ opts = RequestOptions.construct(
669
+ method="get",
670
+ url=path,
671
+ # query params flow in via `options["params"]` (set by
672
+ # make_request_options); no separate `params` kwarg.
673
+ **options,
674
+ )
675
+
676
+ return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
677
+
678
+ def delete(
679
+ self,
680
+ path: str,
681
+ *,
682
+ cast_to: Type[ResponseT],
683
+ options: ExtraRequestOptions = {},
684
+ ) -> ResponseT:
685
+ opts = RequestOptions.construct( # type: ignore
686
+ method="delete",
687
+ url=path,
688
+ # query params flow in via `options["params"]` (set by
689
+ # make_request_options); no separate `params` kwarg.
690
+ **options,
691
+ )
692
+
693
+ return cast(ResponseT, self.request(cast_to, opts))
694
+
695
+ def post_without_retry(
696
+ self,
697
+ path: str,
698
+ *,
699
+ cast_to: Type[ResponseT],
700
+ body: Dict | None = None,
701
+ options: ExtraRequestOptions = {},
702
+ files: RequestFiles | None = None,
703
+ stream: bool = False,
704
+ stream_cls: type[_StreamT] | None = None,
705
+ ) -> ResponseT | _StreamT:
706
+ opts = RequestOptions.construct( # type: ignore
707
+ method="post",
708
+ url=path,
709
+ body=body,
710
+ files=files,
711
+ **options,
712
+ )
713
+
714
+ return cast(
715
+ ResponseT,
716
+ self.request(cast_to, opts, remaining_retries=0, stream=stream, stream_cls=stream_cls),
717
+ )
718
+
719
+ def get_api_list(
720
+ self,
721
+ path: str,
722
+ *,
723
+ model: Type[object],
724
+ page: Type[SyncPageT],
725
+ body: Body | None = None,
726
+ options: ExtraRequestOptions = {},
727
+ method: str = "get",
728
+ ) -> AsyncPageT:
729
+ opts = RequestOptions.construct(method=method, url=path, json_data=body, **options)
730
+ return self._request_api_list(model, page, opts)
731
+
732
+ def _request_api_list(
733
+ self,
734
+ model: Type[object],
735
+ page: Type[SyncPageT],
736
+ options: RequestOptions,
737
+ ) -> AsyncPageT:
738
+ def _parser(resp: AsyncPageT) -> SyncPageT:
739
+ resp._set_private_attributes(
740
+ client=self,
741
+ model=model,
742
+ options=options,
743
+ )
744
+ return resp
745
+
746
+ options.post_parser = _parser
747
+ return self.request(page, options, stream=False)
748
+
749
+ def request(
750
+ self,
751
+ cast_to: Type[ResponseT],
752
+ options: RequestOptions,
753
+ remaining_retries: Optional[int] = None,
754
+ *,
755
+ stream: bool = False,
756
+ stream_cls: type[_StreamT] | None = None,
757
+ ) -> ResponseT | _StreamT:
758
+ return self._request(
759
+ cast_to=cast_to,
760
+ options=options,
761
+ stream=stream,
762
+ stream_cls=stream_cls,
763
+ remaining_retries=remaining_retries,
764
+ )
765
+
766
+ def is_closed(self) -> bool:
767
+ return self._client.is_closed
768
+
769
+ def close(self) -> None:
770
+ """Close the underlying HTTPX client.
771
+
772
+ The client will *not* be usable after this.
773
+ """
774
+ # If an error is thrown while constructing a client, self._client
775
+ # may not be present
776
+ if hasattr(self, "_client"):
777
+ self._client.close()
778
+
779
+ def __enter__(self: _T) -> _T:
780
+ return self
781
+
782
+ def __exit__(
783
+ self,
784
+ exc_type: type[BaseException] | None,
785
+ exc: BaseException | None,
786
+ exc_tb: TracebackType | None,
787
+ ) -> None:
788
+ self.close()
789
+
790
+
791
+ class _DefaultAsyncHttpxClient(httpx.AsyncClient):
792
+ def __init__(self, **kwargs: Any) -> None:
793
+ kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
794
+ kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
795
+ kwargs.setdefault("follow_redirects", True)
796
+ super().__init__(**kwargs)
797
+
798
+
799
+ if TYPE_CHECKING:
800
+ DefaultAsyncHttpxClient = httpx.AsyncClient
801
+ """An alias to `httpx.AsyncClient` that provides the same defaults that this SDK
802
+ uses internally.
803
+
804
+ This is useful because overriding the `http_client` with your own instance of
805
+ `httpx.AsyncClient` will result in httpx's defaults being used, not ours.
806
+ """
807
+ else:
808
+ DefaultAsyncHttpxClient = _DefaultAsyncHttpxClient
809
+
810
+
811
+ class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
812
+ def __del__(self) -> None:
813
+ try:
814
+ # TODO(someday): support non asyncio runtimes here
815
+ asyncio.get_running_loop().create_task(self.aclose())
816
+ except Exception:
817
+ pass
818
+
819
+
820
+ class AsyncAPIClient(BaseClient):
821
+ _client: httpx.AsyncClient
822
+
823
+ def __init__(
824
+ self,
825
+ *,
826
+ base_url: str | URL,
827
+ max_retries: int = DEFAULT_MAX_RETRIES,
828
+ timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
829
+ http_client: httpx.AsyncClient | None = None,
830
+ custom_headers: Dict[str, str] | None = None,
831
+ custom_query: Dict[str, object] | None = None,
832
+ ) -> None:
833
+ if http_client is not None and not isinstance(http_client, httpx.AsyncClient): # pyright: ignore[reportUnnecessaryIsInstance]
834
+ raise TypeError(
835
+ f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got {type(http_client)}"
836
+ )
837
+
838
+ super().__init__(
839
+ base_url=base_url,
840
+ timeout=cast(Timeout, timeout),
841
+ max_retries=max_retries,
842
+ custom_query=custom_query,
843
+ custom_headers=custom_headers,
844
+ )
845
+
846
+ self._client = http_client or AsyncHttpxClientWrapper(
847
+ base_url=self._enforce_trailing_slash(URL(base_url)),
848
+ timeout=cast(Timeout, timeout),
849
+ )
850
+
851
+ async def post(
852
+ self,
853
+ path: str,
854
+ *,
855
+ cast_to: Type[ResponseT],
856
+ body: Dict | None = None,
857
+ options: ExtraRequestOptions = {},
858
+ files: RequestFiles | None = None,
859
+ stream: bool = False,
860
+ stream_cls: type[_AsyncStreamT] | None = None,
861
+ ) -> ResponseT | _AsyncStreamT:
862
+ opts = RequestOptions.construct(
863
+ method="post",
864
+ url=path,
865
+ body=body,
866
+ files=await async_to_httpx_files(files),
867
+ **options,
868
+ )
869
+
870
+ return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
871
+
872
+ async def get(
873
+ self,
874
+ path: str,
875
+ *,
876
+ cast_to: Type[ResponseT],
877
+ options: ExtraRequestOptions = {},
878
+ stream: bool = False,
879
+ stream_cls: type[_AsyncStreamT] | None = None,
880
+ ) -> ResponseT | _AsyncStreamT:
881
+ opts = RequestOptions.construct(
882
+ method="get",
883
+ url=path,
884
+ # query params flow in via `options["params"]` (set by
885
+ # make_request_options); no separate `params` kwarg.
886
+ **options,
887
+ )
888
+
889
+ return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
890
+
891
+ async def delete(
892
+ self,
893
+ path: str,
894
+ *,
895
+ cast_to: Type[ResponseT],
896
+ options: ExtraRequestOptions = {},
897
+ ) -> ResponseT:
898
+ opts = RequestOptions.construct(
899
+ method="delete",
900
+ url=path,
901
+ # query params flow in via `options["params"]` (set by
902
+ # make_request_options); no separate `params` kwarg.
903
+ **options,
904
+ )
905
+
906
+ return await self.request(cast_to, opts)
907
+
908
+ async def post_without_retry(
909
+ self,
910
+ path: str,
911
+ *,
912
+ cast_to: Type[ResponseT],
913
+ body: Dict | None = None,
914
+ options: ExtraRequestOptions = {},
915
+ files: RequestFiles | None = None,
916
+ stream: bool = False,
917
+ stream_cls: type[_AsyncStreamT] | None = None,
918
+ ) -> ResponseT | _AsyncStreamT:
919
+ opts = RequestOptions.construct(
920
+ method="post",
921
+ url=path,
922
+ body=body,
923
+ files=files,
924
+ **options,
925
+ )
926
+
927
+ return await self.request(cast_to, opts, remaining_retries=0, stream=stream, stream_cls=stream_cls)
928
+
929
+ async def get_api_list(
930
+ self,
931
+ path: str,
932
+ *,
933
+ model: Type[object],
934
+ page: Type[AsyncPageT],
935
+ body: Body | None = None,
936
+ options: ExtraRequestOptions = {},
937
+ method: str = "get",
938
+ ) -> AsyncPageT:
939
+ opts = RequestOptions.construct(method=method, url=path, json_data=body, **options)
940
+ return await self._request_api_list(model, page, opts)
941
+
942
+ async def _request_api_list(
943
+ self,
944
+ model: Type[object],
945
+ page: Type[AsyncPageT],
946
+ options: RequestOptions,
947
+ ) -> AsyncPageT:
948
+ def _parser(resp: AsyncPageT) -> SyncPageT:
949
+ resp._set_private_attributes(
950
+ client=self,
951
+ model=model,
952
+ options=options,
953
+ )
954
+ return resp
955
+
956
+ options.post_parser = _parser
957
+
958
+ return await self.request(page, options, stream=False)
959
+
960
+ async def request(
961
+ self,
962
+ cast_to: Type[ResponseT],
963
+ options: RequestOptions,
964
+ remaining_retries: Optional[int] = None,
965
+ *,
966
+ stream: bool = False,
967
+ stream_cls: type[_StreamT] | None = None,
968
+ ) -> ResponseT | _StreamT:
969
+ return await self._request(
970
+ cast_to=cast_to,
971
+ options=options,
972
+ stream=stream,
973
+ stream_cls=stream_cls,
974
+ remaining_retries=remaining_retries,
975
+ )
976
+
977
+ async def _request(
978
+ self,
979
+ *,
980
+ cast_to: Type[ResponseT],
981
+ options: RequestOptions,
982
+ remaining_retries: int | None,
983
+ stream: bool,
984
+ stream_cls: type[_AsyncStreamT] | None,
985
+ ) -> ResponseT | _AsyncStreamT:
986
+ retries = self._remaining_retries(remaining_retries, options)
987
+ request = self._build_request(options)
988
+ req_id = request.headers.get(CLIENT_REQUEST_HEADER, "")
989
+ try:
990
+ response = await self._client.send(
991
+ request,
992
+ stream=stream or self._should_stream_response_body(request=request),
993
+ )
994
+ except httpx.TimeoutException as err:
995
+ if retries > 0:
996
+ return await self._retry_request(
997
+ options,
998
+ cast_to,
999
+ retries,
1000
+ stream=stream,
1001
+ stream_cls=stream_cls,
1002
+ response_headers=None,
1003
+ )
1004
+
1005
+ log.debug("Raising timeout error")
1006
+ raise ArkAPITimeoutError(request=request, request_id=req_id) from err
1007
+ except Exception as err:
1008
+ log.debug("Encountered Exception", exc_info=True)
1009
+
1010
+ if retries > 0:
1011
+ return await self._retry_request(
1012
+ options,
1013
+ cast_to,
1014
+ retries,
1015
+ stream=stream,
1016
+ stream_cls=stream_cls,
1017
+ response_headers=None,
1018
+ )
1019
+
1020
+ log.debug("Raising connection error")
1021
+ raise ArkAPIConnectionError(request=request, request_id=req_id) from err
1022
+
1023
+ log.debug(
1024
+ 'HTTP Request: %s %s "%i %s"',
1025
+ request.method,
1026
+ request.url,
1027
+ response.status_code,
1028
+ response.reason_phrase,
1029
+ )
1030
+
1031
+ try:
1032
+ response.raise_for_status()
1033
+ except httpx.HTTPStatusError as err: # thrown on 4xx and 5xx status code
1034
+ log.debug("Encountered httpx.HTTPStatusError", exc_info=True)
1035
+
1036
+ if retries > 0 and self._should_retry(err.response):
1037
+ await err.response.aclose()
1038
+ return await self._retry_request(
1039
+ options,
1040
+ cast_to,
1041
+ retries,
1042
+ err.response.headers,
1043
+ stream=stream,
1044
+ stream_cls=stream_cls,
1045
+ )
1046
+
1047
+ # If the response is streamed then we need to explicitly read the response
1048
+ # to completion before attempting to access the response text.
1049
+ if not err.response.is_closed:
1050
+ await err.response.aread()
1051
+
1052
+ log.debug("Re-raising status error")
1053
+ raise self._make_status_error_from_response(err.response, request_id=req_id) from None
1054
+
1055
+ return await self._process_response(
1056
+ cast_to=cast_to,
1057
+ response=response,
1058
+ stream=stream,
1059
+ stream_cls=stream_cls,
1060
+ options=options,
1061
+ )
1062
+
1063
+ async def _retry_request(
1064
+ self,
1065
+ options: RequestOptions,
1066
+ cast_to: Type[ResponseT],
1067
+ remaining_retries: int,
1068
+ response_headers: httpx.Headers | None,
1069
+ *,
1070
+ stream: bool,
1071
+ stream_cls: type[_AsyncStreamT] | None,
1072
+ ) -> ResponseT | _AsyncStreamT:
1073
+ remaining = remaining_retries - 1
1074
+ if remaining == 1:
1075
+ log.debug("1 retry left")
1076
+ else:
1077
+ log.debug("%i retries left", remaining)
1078
+
1079
+ timeout = self._calculate_retry_timeout(remaining, options, response_headers)
1080
+ log.info("Retrying request to %s in %f seconds", options.url, timeout)
1081
+
1082
+ await anyio.sleep(timeout)
1083
+
1084
+ return await self._request(
1085
+ options=options,
1086
+ cast_to=cast_to,
1087
+ remaining_retries=remaining,
1088
+ stream=stream,
1089
+ stream_cls=stream_cls,
1090
+ )
1091
+
1092
+ async def _process_response(
1093
+ self,
1094
+ *,
1095
+ cast_to: Type[ResponseT],
1096
+ options: RequestOptions,
1097
+ response: httpx.Response,
1098
+ stream: bool,
1099
+ stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None,
1100
+ ) -> ResponseT:
1101
+ if cast_to == httpx.Response:
1102
+ return cast(ResponseT, response)
1103
+
1104
+ api_response = ArkAsyncAPIResponse(
1105
+ raw=response,
1106
+ client=self,
1107
+ cast_to=cast("type[ResponseT]", cast_to), # pyright: ignore[reportUnnecessaryCast]
1108
+ stream=stream,
1109
+ stream_cls=stream_cls,
1110
+ options=options,
1111
+ )
1112
+ if bool(response.request.headers.get(RAW_RESPONSE_HEADER)):
1113
+ return cast(ResponseT, api_response)
1114
+
1115
+ return await api_response.parse()
1116
+
1117
+ def is_closed(self) -> bool:
1118
+ return self._client.is_closed
1119
+
1120
+ async def close(self) -> None:
1121
+ """Close the underlying HTTPX client.
1122
+
1123
+ The client will *not* be usable after this.
1124
+ """
1125
+ await self._client.aclose()
1126
+
1127
+ async def __aenter__(self: _T) -> _T:
1128
+ return self
1129
+
1130
+ async def __aexit__(
1131
+ self,
1132
+ exc_type: type[BaseException] | None,
1133
+ exc: BaseException | None,
1134
+ exc_tb: TracebackType | None,
1135
+ ) -> None:
1136
+ await self.close()
1137
+
1138
+
1139
+ class PageInfo:
1140
+ """Stores the necessary information to build the request to retrieve the next page.
1141
+
1142
+ Either `url` or `params` must be set.
1143
+ """
1144
+
1145
+ url: URL | NotGiven
1146
+ params: Query | NotGiven
1147
+ json: Body | NotGiven
1148
+
1149
+ def __init__(
1150
+ self,
1151
+ *,
1152
+ url: URL | NotGiven = NOT_GIVEN,
1153
+ json: Body | NotGiven = NOT_GIVEN,
1154
+ params: Query | NotGiven = NOT_GIVEN,
1155
+ ) -> None:
1156
+ self.url = url
1157
+ self.json = json
1158
+ self.params = params
1159
+
1160
+ @override
1161
+ def __repr__(self) -> str:
1162
+ if self.url:
1163
+ return f"{self.__class__.__name__}(url={self.url})"
1164
+ if self.json:
1165
+ return f"{self.__class__.__name__}(json={self.json})"
1166
+ return f"{self.__class__.__name__}(params={self.params})"
1167
+
1168
+
1169
+ class BasePage(GenericModel, Generic[_T]):
1170
+ """
1171
+ Defines the core interface for pagination.
1172
+
1173
+ Type Args:
1174
+ ModelT: The pydantic model that represents an item in the response.
1175
+
1176
+ Methods:
1177
+ has_next_page(): Check if there is another page available
1178
+ next_page_info(): Get the necessary information to make a request for the next page
1179
+ """
1180
+
1181
+ _options: RequestOptions = PrivateAttr()
1182
+ _model: Type[_T] = PrivateAttr()
1183
+
1184
+ def has_next_page(self) -> bool:
1185
+ items = self._get_page_items()
1186
+ if not items:
1187
+ return False
1188
+ return self.next_page_info() is not None
1189
+
1190
+ def next_page_info(self) -> Optional[PageInfo]: ...
1191
+
1192
+ def _get_page_items(self) -> Iterable[_T]: # type: ignore[empty-body]
1193
+ ...
1194
+
1195
+ def _params_from_url(self, url: URL) -> httpx.QueryParams:
1196
+ # TODO: do we have to preprocess params here?
1197
+ return httpx.QueryParams(cast(Any, self._options.params)).merge(url.params)
1198
+
1199
+ def _info_to_options(self, info: PageInfo) -> RequestOptions:
1200
+ options = model_copy(self._options)
1201
+ options._strip_raw_response_header()
1202
+
1203
+ if not isinstance(info.params, NotGiven):
1204
+ options.params = {**options.params, **info.params}
1205
+ return options
1206
+
1207
+ if not isinstance(info.url, NotGiven):
1208
+ params = self._params_from_url(info.url)
1209
+ url = info.url.copy_with(params=params)
1210
+ options.params = dict(url.params)
1211
+ options.url = str(url)
1212
+ return options
1213
+
1214
+ if not isinstance(info.json, NotGiven):
1215
+ if not is_mapping(info.json):
1216
+ raise TypeError("Pagination is only supported with mappings")
1217
+
1218
+ if not options.json_data:
1219
+ options.json_data = {**info.json}
1220
+ else:
1221
+ if not is_mapping(options.json_data):
1222
+ raise TypeError("Pagination is only supported with mappings")
1223
+
1224
+ options.json_data = {**options.json_data, **info.json}
1225
+ return options
1226
+
1227
+ raise ValueError("Unexpected PageInfo state")
1228
+
1229
+
1230
+ class BaseSyncPage(BasePage[_T], Generic[_T]):
1231
+ _client: SyncAPIClient = pydantic.PrivateAttr()
1232
+
1233
+ def _set_private_attributes(
1234
+ self,
1235
+ client: SyncAPIClient,
1236
+ model: Type[_T],
1237
+ options: RequestOptions,
1238
+ ) -> None:
1239
+ if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
1240
+ self.__pydantic_private__ = {}
1241
+
1242
+ self._model = model
1243
+ self._client = client
1244
+ self._options = options
1245
+
1246
+ # Pydantic uses a custom `__iter__` method to support casting BaseModels
1247
+ # to dictionaries. e.g. dict(model).
1248
+ # As we want to support `for item in page`, this is inherently incompatible
1249
+ # with the default pydantic behaviour. It is not possible to support both
1250
+ # use cases at once. Fortunately, this is not a big deal as all other pydantic
1251
+ # methods should continue to work as expected as there is an alternative method
1252
+ # to cast a model to a dictionary, model.dict(), which is used internally
1253
+ # by pydantic.
1254
+ def __iter__(self) -> Iterator[_T]: # type: ignore
1255
+ for page in self.iter_pages():
1256
+ for item in page._get_page_items():
1257
+ yield item
1258
+
1259
+ def iter_pages(self: SyncPageT) -> Iterator[SyncPageT]:
1260
+ page = self
1261
+ while True:
1262
+ yield page
1263
+ if page.has_next_page():
1264
+ page = page.get_next_page()
1265
+ else:
1266
+ return
1267
+
1268
+ def get_next_page(self: SyncPageT) -> SyncPageT:
1269
+ info = self.next_page_info()
1270
+ if not info:
1271
+ raise RuntimeError(
1272
+ "No next page expected; please check `.has_next_page()` before calling `.get_next_page()`."
1273
+ )
1274
+
1275
+ options = self._info_to_options(info)
1276
+ return self._client._request_api_list(self._model, page=self.__class__, options=options)
1277
+
1278
+
1279
+ class AsyncPaginator(Generic[_T, AsyncPageT]):
1280
+ def __init__(
1281
+ self,
1282
+ client: AsyncAPIClient,
1283
+ options: RequestOptions,
1284
+ page_cls: Type[AsyncPageT],
1285
+ model: Type[_T],
1286
+ ) -> None:
1287
+ self._model = model
1288
+ self._client = client
1289
+ self._options = options
1290
+ self._page_cls = page_cls
1291
+
1292
+ def __await__(self) -> Generator[Any, None, AsyncPageT]:
1293
+ return self._get_page().__await__()
1294
+
1295
+ async def _get_page(self) -> AsyncPageT:
1296
+ def _parser(resp: AsyncPageT) -> AsyncPageT:
1297
+ resp._set_private_attributes(
1298
+ model=self._model,
1299
+ options=self._options,
1300
+ client=self._client,
1301
+ )
1302
+ return resp
1303
+
1304
+ self._options.post_parser = _parser
1305
+
1306
+ return await self._client.request(self._page_cls, self._options)
1307
+
1308
+ async def __aiter__(self) -> AsyncIterator[_T]:
1309
+ # https://github.com/microsoft/pyright/issues/3464
1310
+ page = cast(
1311
+ AsyncPageT,
1312
+ await self, # type: ignore
1313
+ )
1314
+ async for item in page:
1315
+ yield item
1316
+
1317
+
1318
+ class BaseAsyncPage(BasePage[_T], Generic[_T]):
1319
+ _client: AsyncAPIClient = pydantic.PrivateAttr()
1320
+
1321
+ def _set_private_attributes(
1322
+ self,
1323
+ model: Type[_T],
1324
+ client: AsyncAPIClient,
1325
+ options: RequestOptions,
1326
+ ) -> None:
1327
+ if PYDANTIC_V2 and getattr(self, "__pydantic_private__", None) is None:
1328
+ self.__pydantic_private__ = {}
1329
+
1330
+ self._model = model
1331
+ self._client = client
1332
+ self._options = options
1333
+
1334
+ async def __aiter__(self) -> AsyncIterator[_T]:
1335
+ async for page in self.iter_pages():
1336
+ for item in page._get_page_items():
1337
+ yield item
1338
+
1339
+ async def iter_pages(self: AsyncPageT) -> AsyncIterator[AsyncPageT]:
1340
+ page = self
1341
+ while True:
1342
+ yield page
1343
+ if page.has_next_page():
1344
+ page = await page.get_next_page()
1345
+ else:
1346
+ return
1347
+
1348
+ async def get_next_page(self: AsyncPageT) -> AsyncPageT:
1349
+ info = self.next_page_info()
1350
+ if not info:
1351
+ raise RuntimeError(
1352
+ "No next page expected; please check `.has_next_page()` before calling `.get_next_page()`."
1353
+ )
1354
+
1355
+ options = self._info_to_options(info)
1356
+ return await self._client._request_api_list(self._model, page=self.__class__, options=options)
1357
+
1358
+
1359
+ class ForceMultipartDict(Dict[str, None]):
1360
+ def __bool__(self) -> bool:
1361
+ return True
1362
+
1363
+
1364
+ def _merge_mappings(
1365
+ obj1: Mapping[_T_co, Union[_T, None]],
1366
+ obj2: Mapping[_T_co, Union[_T, None]],
1367
+ ) -> Dict[_T_co, _T]:
1368
+ """Merge two mappings of the same type, removing any values that are instances of `Omit`.
1369
+
1370
+ In cases with duplicate keys the second mapping takes precedence.
1371
+ """
1372
+ merged = {**obj1, **obj2}
1373
+ return {key: value for key, value in merged.items() if value is not None}