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.
- arkruntime/__init__.py +11 -0
- arkruntime/_base_client.py +1373 -0
- arkruntime/_client.py +585 -0
- arkruntime/_compat.py +265 -0
- arkruntime/_constants.py +55 -0
- arkruntime/_exceptions.py +188 -0
- arkruntime/_files.py +122 -0
- arkruntime/_legacy_response.py +438 -0
- arkruntime/_managed_agents_serialize.py +55 -0
- arkruntime/_models.py +733 -0
- arkruntime/_qs.py +164 -0
- arkruntime/_request_options.py +118 -0
- arkruntime/_resource.py +41 -0
- arkruntime/_response.py +599 -0
- arkruntime/_streaming.py +460 -0
- arkruntime/_types.py +207 -0
- arkruntime/_utils/__init__.py +144 -0
- arkruntime/_utils/_key_agreement.py +217 -0
- arkruntime/_utils/_logs.py +28 -0
- arkruntime/_utils/_model_breaker.py +87 -0
- arkruntime/_utils/_streams.py +17 -0
- arkruntime/_utils/_transform.py +463 -0
- arkruntime/_utils/_typing.py +157 -0
- arkruntime/_utils/_utils.py +473 -0
- arkruntime/common/__init__.py +6 -0
- arkruntime/common/_parsing/__init__.py +31 -0
- arkruntime/common/_parsing/_completions.py +272 -0
- arkruntime/common/_parsing/_responses.py +174 -0
- arkruntime/common/_pydantic.py +166 -0
- arkruntime/common/_tools.py +85 -0
- arkruntime/common/streaming/__init__.py +4 -0
- arkruntime/common/streaming/_deltas.py +68 -0
- arkruntime/common/streaming/chat/__init__.py +49 -0
- arkruntime/common/streaming/chat/_completions.py +732 -0
- arkruntime/common/streaming/chat/_events.py +96 -0
- arkruntime/common/streaming/chat/_types.py +28 -0
- arkruntime/pagination.py +128 -0
- arkruntime/resources/__init__.py +75 -0
- arkruntime/resources/agents/__init__.py +3 -0
- arkruntime/resources/agents/agents.py +372 -0
- arkruntime/resources/batch/__init__.py +6 -0
- arkruntime/resources/batch/_utils.py +156 -0
- arkruntime/resources/batch/batch.py +40 -0
- arkruntime/resources/batch/chat/__init__.py +6 -0
- arkruntime/resources/batch/chat/chat.py +22 -0
- arkruntime/resources/batch/chat/completions.py +217 -0
- arkruntime/resources/batch/embeddings.py +150 -0
- arkruntime/resources/batch/multimodal_embeddings.py +160 -0
- arkruntime/resources/beta/__init__.py +4 -0
- arkruntime/resources/beta/beta.py +73 -0
- arkruntime/resources/beta/chat/__init__.py +13 -0
- arkruntime/resources/beta/chat/chat.py +23 -0
- arkruntime/resources/beta/chat/completions.py +356 -0
- arkruntime/resources/chat/__init__.py +7 -0
- arkruntime/resources/chat/chat.py +23 -0
- arkruntime/resources/chat/completions.py +242 -0
- arkruntime/resources/content_generation/__init__.py +7 -0
- arkruntime/resources/content_generation/content_generation.py +21 -0
- arkruntime/resources/content_generation/tasks.py +331 -0
- arkruntime/resources/embeddings/__init__.py +6 -0
- arkruntime/resources/embeddings/embeddings.py +140 -0
- arkruntime/resources/encryption.py +187 -0
- arkruntime/resources/environments/__init__.py +3 -0
- arkruntime/resources/environments/environments.py +216 -0
- arkruntime/resources/files/__init__.py +6 -0
- arkruntime/resources/files/files.py +401 -0
- arkruntime/resources/images/__init__.py +10 -0
- arkruntime/resources/images/images.py +152 -0
- arkruntime/resources/memory_stores/__init__.py +7 -0
- arkruntime/resources/memory_stores/memories.py +262 -0
- arkruntime/resources/memory_stores/memory_stores.py +223 -0
- arkruntime/resources/multimodal_embeddings/__init__.py +9 -0
- arkruntime/resources/multimodal_embeddings/multimodal_embeddings.py +150 -0
- arkruntime/resources/responses/__init__.py +8 -0
- arkruntime/resources/responses/input_items.py +241 -0
- arkruntime/resources/responses/responses.py +467 -0
- arkruntime/resources/sessions/__init__.py +24 -0
- arkruntime/resources/sessions/session_events.py +336 -0
- arkruntime/resources/sessions/session_resources.py +89 -0
- arkruntime/resources/sessions/session_threads.py +275 -0
- arkruntime/resources/sessions/sessions.py +331 -0
- arkruntime/resources/skills/__init__.py +3 -0
- arkruntime/resources/skills/skills.py +112 -0
- arkruntime/resources/tokenization/__init__.py +9 -0
- arkruntime/resources/tokenization/tokenization.py +131 -0
- arkruntime/resources/vaults/__init__.py +4 -0
- arkruntime/resources/vaults/credentials.py +253 -0
- arkruntime/resources/vaults/vaults.py +197 -0
- arkruntime/types/__init__.py +7 -0
- arkruntime/types/agent/__init__.py +56 -0
- arkruntime/types/agent/_init_extras_shim.py +12 -0
- arkruntime/types/agent/agent.py +86 -0
- arkruntime/types/agent/agent_ref.py +32 -0
- arkruntime/types/agent/agent_ref_type.py +18 -0
- arkruntime/types/agent/agent_skill_ref.py +32 -0
- arkruntime/types/agent/create_agent_request.py +65 -0
- arkruntime/types/agent/delete_agent_response.py +20 -0
- arkruntime/types/agent/list_agents_response.py +32 -0
- arkruntime/types/agent/mcp_server.py +30 -0
- arkruntime/types/agent/mcp_server_type.py +16 -0
- arkruntime/types/agent/model_config.py +28 -0
- arkruntime/types/agent/model_speed.py +18 -0
- arkruntime/types/agent/multiagent_config.py +29 -0
- arkruntime/types/agent/multiagent_type.py +16 -0
- arkruntime/types/agent/permission_policy.py +22 -0
- arkruntime/types/agent/permission_policy_type.py +18 -0
- arkruntime/types/agent/skill_ref_type.py +19 -0
- arkruntime/types/agent/tag.py +26 -0
- arkruntime/types/agent/tool_config.py +32 -0
- arkruntime/types/agent/tool_default_config.py +28 -0
- arkruntime/types/agent/tool_item.py +57 -0
- arkruntime/types/agent/update_agent_request.py +70 -0
- arkruntime/types/chat/__init__.py +212 -0
- arkruntime/types/chat/_init_extras_shim.py +73 -0
- arkruntime/types/chat/chat_completion_choice_logprobs.py +20 -0
- arkruntime/types/chat/chat_completion_content_part.py +32 -0
- arkruntime/types/chat/chat_completion_content_part_audio.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_audio_input_audio.py +30 -0
- arkruntime/types/chat/chat_completion_content_part_audio_input_audio_param.py +25 -0
- arkruntime/types/chat/chat_completion_content_part_audio_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_file.py +21 -0
- arkruntime/types/chat/chat_completion_content_part_file_file.py +30 -0
- arkruntime/types/chat/chat_completion_content_part_file_file_param.py +25 -0
- arkruntime/types/chat/chat_completion_content_part_file_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_image.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_image_image_url.py +33 -0
- arkruntime/types/chat/chat_completion_content_part_image_image_url_param.py +28 -0
- arkruntime/types/chat/chat_completion_content_part_image_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_param.py +29 -0
- arkruntime/types/chat/chat_completion_content_part_text.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_text_param.py +19 -0
- arkruntime/types/chat/chat_completion_content_part_video.py +23 -0
- arkruntime/types/chat/chat_completion_content_part_video_param.py +22 -0
- arkruntime/types/chat/chat_completion_content_part_video_video_url.py +36 -0
- arkruntime/types/chat/chat_completion_content_part_video_video_url_param.py +30 -0
- arkruntime/types/chat/chat_completion_message_content.py +17 -0
- arkruntime/types/chat/chat_completion_message_content_param.py +15 -0
- arkruntime/types/chat/chat_completion_message_tool_call.py +29 -0
- arkruntime/types/chat/chat_completion_message_tool_call_chunk.py +31 -0
- arkruntime/types/chat/chat_completion_message_tool_call_chunk_function.py +16 -0
- arkruntime/types/chat/chat_completion_message_tool_call_function.py +23 -0
- arkruntime/types/chat/chat_completion_message_tool_call_function_param.py +22 -0
- arkruntime/types/chat/chat_completion_message_tool_call_param.py +26 -0
- arkruntime/types/chat/chat_completion_named_tool_choice.py +21 -0
- arkruntime/types/chat/chat_completion_named_tool_choice_param.py +22 -0
- arkruntime/types/chat/chat_completion_request.py +129 -0
- arkruntime/types/chat/chat_completion_request_assistant_message.py +39 -0
- arkruntime/types/chat/chat_completion_request_assistant_message_param.py +36 -0
- arkruntime/types/chat/chat_completion_request_message.py +32 -0
- arkruntime/types/chat/chat_completion_request_message_param.py +29 -0
- arkruntime/types/chat/chat_completion_request_param.py +122 -0
- arkruntime/types/chat/chat_completion_request_system_message.py +25 -0
- arkruntime/types/chat/chat_completion_request_system_message_param.py +23 -0
- arkruntime/types/chat/chat_completion_request_tool_message.py +29 -0
- arkruntime/types/chat/chat_completion_request_tool_message_param.py +26 -0
- arkruntime/types/chat/chat_completion_request_user_message.py +29 -0
- arkruntime/types/chat/chat_completion_request_user_message_param.py +27 -0
- arkruntime/types/chat/chat_completion_response.py +52 -0
- arkruntime/types/chat/chat_completion_response_choice.py +36 -0
- arkruntime/types/chat/chat_completion_response_format.py +28 -0
- arkruntime/types/chat/chat_completion_response_format_json_schema.py +33 -0
- arkruntime/types/chat/chat_completion_response_format_json_schema_param.py +31 -0
- arkruntime/types/chat/chat_completion_response_format_param.py +27 -0
- arkruntime/types/chat/chat_completion_response_message.py +37 -0
- arkruntime/types/chat/chat_completion_role.py +16 -0
- arkruntime/types/chat/chat_completion_service_status.py +17 -0
- arkruntime/types/chat/chat_completion_stop.py +13 -0
- arkruntime/types/chat/chat_completion_stop_param.py +11 -0
- arkruntime/types/chat/chat_completion_stream_choice_logprobs.py +17 -0
- arkruntime/types/chat/chat_completion_stream_options.py +22 -0
- arkruntime/types/chat/chat_completion_stream_options_param.py +19 -0
- arkruntime/types/chat/chat_completion_stream_response.py +34 -0
- arkruntime/types/chat/chat_completion_stream_response_choice.py +27 -0
- arkruntime/types/chat/chat_completion_stream_response_delta.py +36 -0
- arkruntime/types/chat/chat_completion_token_logprob.py +26 -0
- arkruntime/types/chat/chat_completion_token_logprob_top_logprob.py +17 -0
- arkruntime/types/chat/chat_completion_tool.py +20 -0
- arkruntime/types/chat/chat_completion_tool_choice.py +18 -0
- arkruntime/types/chat/chat_completion_tool_choice_function.py +13 -0
- arkruntime/types/chat/chat_completion_tool_choice_function_param.py +13 -0
- arkruntime/types/chat/chat_completion_tool_choice_param.py +16 -0
- arkruntime/types/chat/chat_completion_tool_param.py +20 -0
- arkruntime/types/chat/completion_tokens_details.py +16 -0
- arkruntime/types/chat/completion_usage.py +35 -0
- arkruntime/types/chat/error.py +28 -0
- arkruntime/types/chat/error_response.py +15 -0
- arkruntime/types/chat/finish_reason.py +16 -0
- arkruntime/types/chat/function_object.py +35 -0
- arkruntime/types/chat/function_object_param.py +38 -0
- arkruntime/types/chat/image_detail.py +16 -0
- arkruntime/types/chat/image_pixel_limit.py +16 -0
- arkruntime/types/chat/image_pixel_limit_param.py +17 -0
- arkruntime/types/chat/model_fallback_status.py +20 -0
- arkruntime/types/chat/moderation_hit_type.py +14 -0
- arkruntime/types/chat/parsed_chat_completion_shim.py +52 -0
- arkruntime/types/chat/parsed_function_tool_call_shim.py +29 -0
- arkruntime/types/chat/prompt_tokens_details.py +34 -0
- arkruntime/types/chat/reasoning_effort.py +19 -0
- arkruntime/types/chat/request_service_tier.py +15 -0
- arkruntime/types/chat/response_format_type.py +15 -0
- arkruntime/types/chat/response_service_tier.py +15 -0
- arkruntime/types/chat/thinking.py +17 -0
- arkruntime/types/chat/thinking_mode.py +15 -0
- arkruntime/types/chat/thinking_param.py +17 -0
- arkruntime/types/chat/tool_choice_mode.py +15 -0
- arkruntime/types/chat/tool_type.py +13 -0
- arkruntime/types/chat/tool_type_param.py +11 -0
- arkruntime/types/chat/video_image_pixel_limit.py +16 -0
- arkruntime/types/chat/video_image_pixel_limit_param.py +17 -0
- arkruntime/types/completion_usage.py +43 -0
- arkruntime/types/content_generation/__init__.py +66 -0
- arkruntime/types/content_generation/_init_extras_shim.py +12 -0
- arkruntime/types/content_generation/audio_role.py +16 -0
- arkruntime/types/content_generation/audio_url.py +16 -0
- arkruntime/types/content_generation/audio_url_param.py +14 -0
- arkruntime/types/content_generation/content_generation_task.py +125 -0
- arkruntime/types/content_generation/content_item.py +54 -0
- arkruntime/types/content_generation/content_item_param.py +46 -0
- arkruntime/types/content_generation/content_type.py +21 -0
- arkruntime/types/content_generation/create_content_generation_task_request.py +106 -0
- arkruntime/types/content_generation/create_content_generation_task_request_param.py +83 -0
- arkruntime/types/content_generation/create_content_generation_task_response.py +16 -0
- arkruntime/types/content_generation/draft_task.py +16 -0
- arkruntime/types/content_generation/draft_task_param.py +14 -0
- arkruntime/types/content_generation/image_role.py +20 -0
- arkruntime/types/content_generation/image_url.py +16 -0
- arkruntime/types/content_generation/image_url_param.py +14 -0
- arkruntime/types/content_generation/list_content_generation_tasks_response.py +24 -0
- arkruntime/types/content_generation/reasoning_effort.py +16 -0
- arkruntime/types/content_generation/task_content.py +30 -0
- arkruntime/types/content_generation/task_error.py +20 -0
- arkruntime/types/content_generation/task_status.py +21 -0
- arkruntime/types/content_generation/task_usage.py +28 -0
- arkruntime/types/content_generation/tool.py +18 -0
- arkruntime/types/content_generation/tool_param.py +17 -0
- arkruntime/types/content_generation/tool_type.py +13 -0
- arkruntime/types/content_generation/tool_type_param.py +11 -0
- arkruntime/types/content_generation/tool_usage.py +18 -0
- arkruntime/types/content_generation/video_role.py +16 -0
- arkruntime/types/content_generation/video_url.py +16 -0
- arkruntime/types/content_generation/video_url_param.py +14 -0
- arkruntime/types/embedding/__init__.py +30 -0
- arkruntime/types/embedding/_init_extras_shim.py +12 -0
- arkruntime/types/embedding/embedding.py +18 -0
- arkruntime/types/embedding/embedding_input.py +18 -0
- arkruntime/types/embedding/embedding_input_param.py +16 -0
- arkruntime/types/embedding/embedding_item.py +32 -0
- arkruntime/types/embedding/embedding_request.py +39 -0
- arkruntime/types/embedding/embedding_request_param.py +37 -0
- arkruntime/types/embedding/embedding_response.py +41 -0
- arkruntime/types/embedding/embedding_usage.py +24 -0
- arkruntime/types/embedding/encoding_format.py +14 -0
- arkruntime/types/environment/__init__.py +36 -0
- arkruntime/types/environment/_init_extras_shim.py +12 -0
- arkruntime/types/environment/create_environment_request.py +41 -0
- arkruntime/types/environment/delete_environment_response.py +24 -0
- arkruntime/types/environment/env_config.py +38 -0
- arkruntime/types/environment/env_config_type.py +18 -0
- arkruntime/types/environment/environment.py +57 -0
- arkruntime/types/environment/environment_scope.py +18 -0
- arkruntime/types/environment/list_environments_response.py +30 -0
- arkruntime/types/environment/networking_config.py +37 -0
- arkruntime/types/environment/networking_type.py +18 -0
- arkruntime/types/environment/packages_config.py +47 -0
- arkruntime/types/environment/update_environment_request.py +45 -0
- arkruntime/types/file/__init__.py +40 -0
- arkruntime/types/file/_init_extras_shim.py +12 -0
- arkruntime/types/file/file_create_request.py +41 -0
- arkruntime/types/file/file_create_request_param.py +41 -0
- arkruntime/types/file/file_deleted.py +30 -0
- arkruntime/types/file/file_error.py +32 -0
- arkruntime/types/file/file_list_response.py +42 -0
- arkruntime/types/file/file_object.py +71 -0
- arkruntime/types/file/order.py +18 -0
- arkruntime/types/file/preprocess_configs.py +24 -0
- arkruntime/types/file/preprocess_configs_param.py +22 -0
- arkruntime/types/file/purpose.py +18 -0
- arkruntime/types/file/status.py +19 -0
- arkruntime/types/file/tos_storage.py +28 -0
- arkruntime/types/file/tos_storage_param.py +25 -0
- arkruntime/types/file/video.py +26 -0
- arkruntime/types/file/video_param.py +23 -0
- arkruntime/types/images/__init__.py +55 -0
- arkruntime/types/images/_init_extras_shim.py +12 -0
- arkruntime/types/images/bounding_box.py +27 -0
- arkruntime/types/images/create_image_generation_request.py +88 -0
- arkruntime/types/images/create_image_generation_request_param.py +73 -0
- arkruntime/types/images/image_data_item.py +58 -0
- arkruntime/types/images/image_error.py +20 -0
- arkruntime/types/images/image_generation_response.py +43 -0
- arkruntime/types/images/image_generation_stream_event.py +74 -0
- arkruntime/types/images/image_generation_stream_event_type.py +19 -0
- arkruntime/types/images/optimize_prompt_mode.py +18 -0
- arkruntime/types/images/optimize_prompt_options.py +20 -0
- arkruntime/types/images/optimize_prompt_options_param.py +18 -0
- arkruntime/types/images/output_format.py +18 -0
- arkruntime/types/images/response_format.py +18 -0
- arkruntime/types/images/sequential_image_generation_mode.py +18 -0
- arkruntime/types/images/sequential_image_generation_options.py +18 -0
- arkruntime/types/images/sequential_image_generation_options_param.py +16 -0
- arkruntime/types/images/tool.py +18 -0
- arkruntime/types/images/tool_param.py +17 -0
- arkruntime/types/images/tool_type.py +13 -0
- arkruntime/types/images/tool_type_param.py +11 -0
- arkruntime/types/images/tool_usage.py +18 -0
- arkruntime/types/images/usage.py +36 -0
- arkruntime/types/memory/__init__.py +44 -0
- arkruntime/types/memory/_init_extras_shim.py +12 -0
- arkruntime/types/memory/actor.py +26 -0
- arkruntime/types/memory/actor_type.py +16 -0
- arkruntime/types/memory/create_memory_request.py +24 -0
- arkruntime/types/memory/create_memory_store_request.py +30 -0
- arkruntime/types/memory/delete_memory_response.py +26 -0
- arkruntime/types/memory/delete_memory_store_response.py +26 -0
- arkruntime/types/memory/list_memories_order_by.py +18 -0
- arkruntime/types/memory/list_memories_response.py +32 -0
- arkruntime/types/memory/list_memory_stores_response.py +28 -0
- arkruntime/types/memory/memory.py +64 -0
- arkruntime/types/memory/memory_list_item.py +58 -0
- arkruntime/types/memory/memory_list_item_type.py +20 -0
- arkruntime/types/memory/memory_store.py +64 -0
- arkruntime/types/memory/update_memory_request.py +27 -0
- arkruntime/types/memory/update_memory_store_request.py +31 -0
- arkruntime/types/multimodal_embedding/__init__.py +54 -0
- arkruntime/types/multimodal_embedding/_init_extras_shim.py +12 -0
- arkruntime/types/multimodal_embedding/embedding.py +13 -0
- arkruntime/types/multimodal_embedding/embedding_data_item.py +33 -0
- arkruntime/types/multimodal_embedding/embedding_input.py +34 -0
- arkruntime/types/multimodal_embedding/embedding_input_param.py +29 -0
- arkruntime/types/multimodal_embedding/embedding_input_type.py +15 -0
- arkruntime/types/multimodal_embedding/embedding_object.py +14 -0
- arkruntime/types/multimodal_embedding/embedding_usage.py +26 -0
- arkruntime/types/multimodal_embedding/encoding_format.py +14 -0
- arkruntime/types/multimodal_embedding/image_url.py +16 -0
- arkruntime/types/multimodal_embedding/image_url_param.py +14 -0
- arkruntime/types/multimodal_embedding/multi_embedding_config.py +18 -0
- arkruntime/types/multimodal_embedding/multi_embedding_config_param.py +17 -0
- arkruntime/types/multimodal_embedding/multi_embedding_mode.py +14 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_request.py +47 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_request_param.py +39 -0
- arkruntime/types/multimodal_embedding/multi_modal_embedding_response.py +41 -0
- arkruntime/types/multimodal_embedding/prompt_tokens_details.py +20 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_config.py +20 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_config_param.py +18 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_mode.py +14 -0
- arkruntime/types/multimodal_embedding/sparse_embedding_value.py +20 -0
- arkruntime/types/multimodal_embedding/video_url.py +22 -0
- arkruntime/types/multimodal_embedding/video_url_param.py +19 -0
- arkruntime/types/responses/__init__.py +528 -0
- arkruntime/types/responses/_init_extras_shim.py +47 -0
- arkruntime/types/responses/annotation.py +20 -0
- arkruntime/types/responses/annotation_param.py +14 -0
- arkruntime/types/responses/applied_edit.py +22 -0
- arkruntime/types/responses/audio_chunk.py +15 -0
- arkruntime/types/responses/audio_chunking_strategy.py +18 -0
- arkruntime/types/responses/audio_chunking_strategy_param.py +21 -0
- arkruntime/types/responses/cache_mode.py +14 -0
- arkruntime/types/responses/clear_thinking.py +18 -0
- arkruntime/types/responses/clear_thinking_keep.py +18 -0
- arkruntime/types/responses/clear_thinking_keep_param.py +19 -0
- arkruntime/types/responses/clear_thinking_param.py +19 -0
- arkruntime/types/responses/clear_thinking_response.py +16 -0
- arkruntime/types/responses/clear_tool_uses.py +23 -0
- arkruntime/types/responses/clear_tool_uses_inputs.py +18 -0
- arkruntime/types/responses/clear_tool_uses_inputs_param.py +19 -0
- arkruntime/types/responses/clear_tool_uses_param.py +27 -0
- arkruntime/types/responses/clear_tool_uses_response.py +16 -0
- arkruntime/types/responses/content_filter.py +14 -0
- arkruntime/types/responses/content_item.py +36 -0
- arkruntime/types/responses/content_item_audio.py +20 -0
- arkruntime/types/responses/content_item_audio_param.py +23 -0
- arkruntime/types/responses/content_item_file.py +19 -0
- arkruntime/types/responses/content_item_file_param.py +23 -0
- arkruntime/types/responses/content_item_image.py +22 -0
- arkruntime/types/responses/content_item_image_param.py +26 -0
- arkruntime/types/responses/content_item_param.py +29 -0
- arkruntime/types/responses/content_item_text.py +22 -0
- arkruntime/types/responses/content_item_text_param.py +19 -0
- arkruntime/types/responses/content_item_video.py +27 -0
- arkruntime/types/responses/content_item_video_param.py +24 -0
- arkruntime/types/responses/context_management.py +17 -0
- arkruntime/types/responses/context_management_param.py +17 -0
- arkruntime/types/responses/context_management_response.py +17 -0
- arkruntime/types/responses/cover_image.py +26 -0
- arkruntime/types/responses/cover_image_param.py +22 -0
- arkruntime/types/responses/delete_response_response.py +17 -0
- arkruntime/types/responses/doc_citation.py +19 -0
- arkruntime/types/responses/doc_citation_param.py +23 -0
- arkruntime/types/responses/doubao_app_call_block.py +30 -0
- arkruntime/types/responses/doubao_app_call_block_output_text.py +21 -0
- arkruntime/types/responses/doubao_app_call_block_reasoning_search.py +24 -0
- arkruntime/types/responses/doubao_app_call_block_reasoning_text.py +21 -0
- arkruntime/types/responses/doubao_app_call_block_search.py +24 -0
- arkruntime/types/responses/doubao_app_feature.py +20 -0
- arkruntime/types/responses/doubao_app_feature_item.py +18 -0
- arkruntime/types/responses/doubao_app_feature_item_param.py +19 -0
- arkruntime/types/responses/doubao_app_feature_mode.py +14 -0
- arkruntime/types/responses/doubao_app_feature_param.py +23 -0
- arkruntime/types/responses/doubao_app_search_result.py +15 -0
- arkruntime/types/responses/doubao_app_search_text_item.py +15 -0
- arkruntime/types/responses/doubao_app_tool.py +20 -0
- arkruntime/types/responses/doubao_app_tool_param.py +22 -0
- arkruntime/types/responses/edit.py +19 -0
- arkruntime/types/responses/edit_param.py +14 -0
- arkruntime/types/responses/function_tool.py +32 -0
- arkruntime/types/responses/function_tool_param.py +29 -0
- arkruntime/types/responses/image_detail.py +16 -0
- arkruntime/types/responses/image_pixel_limit.py +16 -0
- arkruntime/types/responses/image_pixel_limit_param.py +17 -0
- arkruntime/types/responses/image_process_options.py +15 -0
- arkruntime/types/responses/image_process_options_param.py +15 -0
- arkruntime/types/responses/image_process_tool.py +21 -0
- arkruntime/types/responses/image_process_tool_param.py +25 -0
- arkruntime/types/responses/incomplete_details.py +24 -0
- arkruntime/types/responses/input_item.py +38 -0
- arkruntime/types/responses/input_item_list_params_shim.py +39 -0
- arkruntime/types/responses/input_item_param.py +33 -0
- arkruntime/types/responses/input_tokens_details.py +17 -0
- arkruntime/types/responses/item_agent_tool_call.py +20 -0
- arkruntime/types/responses/item_doubao_app_call.py +22 -0
- arkruntime/types/responses/item_easy_message.py +22 -0
- arkruntime/types/responses/item_easy_message_param.py +26 -0
- arkruntime/types/responses/item_function_image_process.py +24 -0
- arkruntime/types/responses/item_function_knowledge_search.py +21 -0
- arkruntime/types/responses/item_function_mcp_approval_request.py +34 -0
- arkruntime/types/responses/item_function_mcp_approval_request_param.py +28 -0
- arkruntime/types/responses/item_function_mcp_approval_response.py +34 -0
- arkruntime/types/responses/item_function_mcp_approval_response_param.py +28 -0
- arkruntime/types/responses/item_function_mcp_call.py +44 -0
- arkruntime/types/responses/item_function_mcp_call_param.py +38 -0
- arkruntime/types/responses/item_function_mcp_list_tools.py +36 -0
- arkruntime/types/responses/item_function_mcp_list_tools_param.py +30 -0
- arkruntime/types/responses/item_function_tool_call.py +37 -0
- arkruntime/types/responses/item_function_tool_call_output.py +22 -0
- arkruntime/types/responses/item_function_tool_call_output_param.py +26 -0
- arkruntime/types/responses/item_function_tool_call_param.py +32 -0
- arkruntime/types/responses/item_function_web_search.py +21 -0
- arkruntime/types/responses/item_input_message.py +24 -0
- arkruntime/types/responses/item_output_message.py +23 -0
- arkruntime/types/responses/item_reasoning.py +24 -0
- arkruntime/types/responses/item_reasoning_param.py +29 -0
- arkruntime/types/responses/item_reference.py +16 -0
- arkruntime/types/responses/item_status.py +17 -0
- arkruntime/types/responses/item_transcription.py +21 -0
- arkruntime/types/responses/knowledge_search_tool.py +46 -0
- arkruntime/types/responses/knowledge_search_tool_param.py +37 -0
- arkruntime/types/responses/list_input_items_response.py +21 -0
- arkruntime/types/responses/mcp_allowed_tools.py +17 -0
- arkruntime/types/responses/mcp_allowed_tools_filter.py +15 -0
- arkruntime/types/responses/mcp_allowed_tools_filter_param.py +15 -0
- arkruntime/types/responses/mcp_allowed_tools_param.py +13 -0
- arkruntime/types/responses/mcp_approval_mode.py +14 -0
- arkruntime/types/responses/mcp_list_tools_tool.py +30 -0
- arkruntime/types/responses/mcp_list_tools_tool_param.py +25 -0
- arkruntime/types/responses/mcp_require_approval.py +18 -0
- arkruntime/types/responses/mcp_require_approval_param.py +14 -0
- arkruntime/types/responses/mcp_tool.py +24 -0
- arkruntime/types/responses/mcp_tool_approval_filter.py +19 -0
- arkruntime/types/responses/mcp_tool_approval_filter_always.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_always_param.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_never.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_never_param.py +15 -0
- arkruntime/types/responses/mcp_tool_approval_filter_param.py +20 -0
- arkruntime/types/responses/mcp_tool_param.py +30 -0
- arkruntime/types/responses/message_content.py +15 -0
- arkruntime/types/responses/message_content_param.py +13 -0
- arkruntime/types/responses/message_role.py +16 -0
- arkruntime/types/responses/order.py +18 -0
- arkruntime/types/responses/output_content_item.py +23 -0
- arkruntime/types/responses/output_content_item_param.py +18 -0
- arkruntime/types/responses/output_content_item_reasoning_text.py +19 -0
- arkruntime/types/responses/output_content_item_reasoning_text_param.py +21 -0
- arkruntime/types/responses/output_content_item_text.py +19 -0
- arkruntime/types/responses/output_content_item_text_param.py +21 -0
- arkruntime/types/responses/output_item.py +46 -0
- arkruntime/types/responses/output_tokens_details.py +13 -0
- arkruntime/types/responses/parsed_response_shim.py +106 -0
- arkruntime/types/responses/reasoning.py +17 -0
- arkruntime/types/responses/reasoning_effort.py +19 -0
- arkruntime/types/responses/reasoning_param.py +17 -0
- arkruntime/types/responses/reasoning_summary_part.py +16 -0
- arkruntime/types/responses/reasoning_summary_part_param.py +17 -0
- arkruntime/types/responses/response.py +58 -0
- arkruntime/types/responses/response_agent_tool_call_completed_event.py +19 -0
- arkruntime/types/responses/response_agent_tool_call_in_progress_event.py +19 -0
- arkruntime/types/responses/response_caching.py +18 -0
- arkruntime/types/responses/response_caching_param.py +19 -0
- arkruntime/types/responses/response_completed_event.py +28 -0
- arkruntime/types/responses/response_content_part_added_event.py +22 -0
- arkruntime/types/responses/response_content_part_done_event.py +22 -0
- arkruntime/types/responses/response_created_event.py +28 -0
- arkruntime/types/responses/response_doubao_app_call_block_added_event.py +21 -0
- arkruntime/types/responses/response_doubao_app_call_block_done_event.py +21 -0
- arkruntime/types/responses/response_doubao_app_call_completed_event.py +22 -0
- arkruntime/types/responses/response_doubao_app_call_failed_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_output_text_delta_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_output_text_done_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_completed_event.py +24 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_search_searching_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_text_delta_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_reasoning_text_done_event.py +20 -0
- arkruntime/types/responses/response_doubao_app_call_search_completed_event.py +24 -0
- arkruntime/types/responses/response_doubao_app_call_search_in_progress_event.py +19 -0
- arkruntime/types/responses/response_doubao_app_call_search_searching_event.py +20 -0
- arkruntime/types/responses/response_error.py +20 -0
- arkruntime/types/responses/response_error_event.py +34 -0
- arkruntime/types/responses/response_failed_event.py +28 -0
- arkruntime/types/responses/response_function_call_arguments_delta_event.py +34 -0
- arkruntime/types/responses/response_function_call_arguments_done_event.py +31 -0
- arkruntime/types/responses/response_image_process_action.py +16 -0
- arkruntime/types/responses/response_image_process_call_completed_event.py +22 -0
- arkruntime/types/responses/response_image_process_call_in_progress_event.py +21 -0
- arkruntime/types/responses/response_image_process_call_processing_event.py +22 -0
- arkruntime/types/responses/response_image_process_error.py +13 -0
- arkruntime/types/responses/response_in_progress_event.py +28 -0
- arkruntime/types/responses/response_includable.py +15 -0
- arkruntime/types/responses/response_incomplete_event.py +28 -0
- arkruntime/types/responses/response_knowledge_search_call_completed_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_failed_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_in_progress_event.py +21 -0
- arkruntime/types/responses/response_knowledge_search_call_searching_event.py +21 -0
- arkruntime/types/responses/response_mcp_approval_request_event.py +20 -0
- arkruntime/types/responses/response_mcp_call_arguments_delta_event.py +35 -0
- arkruntime/types/responses/response_mcp_call_arguments_done_event.py +34 -0
- arkruntime/types/responses/response_mcp_call_completed_event.py +30 -0
- arkruntime/types/responses/response_mcp_call_failed_event.py +30 -0
- arkruntime/types/responses/response_mcp_call_in_progress_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_completed_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_failed_event.py +30 -0
- arkruntime/types/responses/response_mcp_list_tools_in_progress_event.py +30 -0
- arkruntime/types/responses/response_output_item_added_event.py +20 -0
- arkruntime/types/responses/response_output_item_done_event.py +20 -0
- arkruntime/types/responses/response_output_text_annotation_added_event.py +46 -0
- arkruntime/types/responses/response_reasoning_raw_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_raw_text_done_event.py +38 -0
- arkruntime/types/responses/response_reasoning_summary_part_added_event.py +22 -0
- arkruntime/types/responses/response_reasoning_summary_part_done_event.py +22 -0
- arkruntime/types/responses/response_reasoning_summary_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_summary_text_done_event.py +38 -0
- arkruntime/types/responses/response_reasoning_text_delta_event.py +38 -0
- arkruntime/types/responses/response_reasoning_text_done_event.py +38 -0
- arkruntime/types/responses/response_status.py +16 -0
- arkruntime/types/responses/response_stream_event.py +216 -0
- arkruntime/types/responses/response_text_config.py +15 -0
- arkruntime/types/responses/response_text_config_param.py +16 -0
- arkruntime/types/responses/response_text_delta_event.py +38 -0
- arkruntime/types/responses/response_text_done_event.py +38 -0
- arkruntime/types/responses/response_transcription_part_added_event.py +22 -0
- arkruntime/types/responses/response_transcription_part_done_event.py +22 -0
- arkruntime/types/responses/response_transcription_text_delta_event.py +46 -0
- arkruntime/types/responses/response_transcription_text_done_event.py +52 -0
- arkruntime/types/responses/response_usage.py +47 -0
- arkruntime/types/responses/response_web_search_call_completed_event.py +30 -0
- arkruntime/types/responses/response_web_search_call_in_progress_event.py +30 -0
- arkruntime/types/responses/response_web_search_call_searching_event.py +30 -0
- arkruntime/types/responses/responses_input.py +15 -0
- arkruntime/types/responses/responses_input_param.py +13 -0
- arkruntime/types/responses/responses_request.py +50 -0
- arkruntime/types/responses/responses_request_param.py +73 -0
- arkruntime/types/responses/service_tier.py +14 -0
- arkruntime/types/responses/session.py +13 -0
- arkruntime/types/responses/session_param.py +13 -0
- arkruntime/types/responses/text_format.py +22 -0
- arkruntime/types/responses/text_format_param.py +25 -0
- arkruntime/types/responses/text_format_type.py +15 -0
- arkruntime/types/responses/text_translation_options.py +14 -0
- arkruntime/types/responses/thinking.py +17 -0
- arkruntime/types/responses/thinking_mode.py +15 -0
- arkruntime/types/responses/thinking_param.py +17 -0
- arkruntime/types/responses/thinking_turns_param.py +16 -0
- arkruntime/types/responses/thinking_turns_param_param.py +17 -0
- arkruntime/types/responses/tool.py +34 -0
- arkruntime/types/responses/tool_choice.py +16 -0
- arkruntime/types/responses/tool_choice_function.py +22 -0
- arkruntime/types/responses/tool_choice_function_param.py +19 -0
- arkruntime/types/responses/tool_choice_knowledge_search.py +15 -0
- arkruntime/types/responses/tool_choice_knowledge_search_param.py +15 -0
- arkruntime/types/responses/tool_choice_mcp.py +26 -0
- arkruntime/types/responses/tool_choice_mcp_param.py +22 -0
- arkruntime/types/responses/tool_choice_options.py +15 -0
- arkruntime/types/responses/tool_choice_param.py +14 -0
- arkruntime/types/responses/tool_choice_web_search.py +15 -0
- arkruntime/types/responses/tool_choice_web_search_param.py +15 -0
- arkruntime/types/responses/tool_name_list.py +15 -0
- arkruntime/types/responses/tool_name_list_param.py +15 -0
- arkruntime/types/responses/tool_param.py +25 -0
- arkruntime/types/responses/tool_usage.py +27 -0
- arkruntime/types/responses/tool_usage_details.py +30 -0
- arkruntime/types/responses/tool_uses_keep.py +16 -0
- arkruntime/types/responses/tool_uses_keep_param.py +17 -0
- arkruntime/types/responses/tool_uses_trigger.py +16 -0
- arkruntime/types/responses/tool_uses_trigger_param.py +17 -0
- arkruntime/types/responses/transcription_part.py +19 -0
- arkruntime/types/responses/truncation_mode.py +14 -0
- arkruntime/types/responses/typed_tool_choice.py +30 -0
- arkruntime/types/responses/typed_tool_choice_param.py +21 -0
- arkruntime/types/responses/url_citation.py +26 -0
- arkruntime/types/responses/url_citation_param.py +35 -0
- arkruntime/types/responses/user_location.py +34 -0
- arkruntime/types/responses/user_location_param.py +28 -0
- arkruntime/types/responses/web_search_action.py +16 -0
- arkruntime/types/responses/web_search_source.py +16 -0
- arkruntime/types/responses/web_search_tool.py +22 -0
- arkruntime/types/responses/web_search_tool_param.py +26 -0
- arkruntime/types/session/__init__.py +154 -0
- arkruntime/types/session/_init_extras_shim.py +88 -0
- arkruntime/types/session/agent_identifier.py +19 -0
- arkruntime/types/session/agent_ref.py +31 -0
- arkruntime/types/session/base64_document_source.py +27 -0
- arkruntime/types/session/base64_image_source.py +27 -0
- arkruntime/types/session/cache_creation.py +26 -0
- arkruntime/types/session/create_session_request.py +50 -0
- arkruntime/types/session/create_session_resource_request.py +29 -0
- arkruntime/types/session/delete_session_response.py +24 -0
- arkruntime/types/session/document_source.py +34 -0
- arkruntime/types/session/file_document_source.py +23 -0
- arkruntime/types/session/file_image_source.py +23 -0
- arkruntime/types/session/image_source.py +28 -0
- arkruntime/types/session/list_session_events_response_wire.py +31 -0
- arkruntime/types/session/list_session_resources_response.py +24 -0
- arkruntime/types/session/list_session_threads_response.py +28 -0
- arkruntime/types/session/list_sessions_order.py +18 -0
- arkruntime/types/session/list_sessions_response.py +28 -0
- arkruntime/types/session/managed_agents_agent_message_preview.py +27 -0
- arkruntime/types/session/managed_agents_agent_thinking_preview.py +27 -0
- arkruntime/types/session/managed_agents_delta_content.py +34 -0
- arkruntime/types/session/managed_agents_delta_event.py +34 -0
- arkruntime/types/session/managed_agents_delta_text_block.py +27 -0
- arkruntime/types/session/managed_agents_document_block.py +33 -0
- arkruntime/types/session/managed_agents_event_params.py +57 -0
- arkruntime/types/session/managed_agents_file_rubric_params.py +23 -0
- arkruntime/types/session/managed_agents_image_block.py +25 -0
- arkruntime/types/session/managed_agents_message_content_block.py +30 -0
- arkruntime/types/session/managed_agents_rubric.py +26 -0
- arkruntime/types/session/managed_agents_search_result_block.py +38 -0
- arkruntime/types/session/managed_agents_session_event.py +34 -0
- arkruntime/types/session/managed_agents_start_event.py +31 -0
- arkruntime/types/session/managed_agents_start_event_preview.py +27 -0
- arkruntime/types/session/managed_agents_stream_preview_event.py +26 -0
- arkruntime/types/session/managed_agents_system_content_block.py +23 -0
- arkruntime/types/session/managed_agents_system_message_event_params.py +34 -0
- arkruntime/types/session/managed_agents_text_block.py +23 -0
- arkruntime/types/session/managed_agents_text_rubric_params.py +23 -0
- arkruntime/types/session/managed_agents_tool_result_content_block.py +34 -0
- arkruntime/types/session/managed_agents_user_custom_tool_result_event_params.py +44 -0
- arkruntime/types/session/managed_agents_user_define_outcome_event_params.py +45 -0
- arkruntime/types/session/managed_agents_user_interrupt_event_params.py +31 -0
- arkruntime/types/session/managed_agents_user_message_event_params.py +34 -0
- arkruntime/types/session/managed_agents_user_tool_confirmation_event_params.py +46 -0
- arkruntime/types/session/managed_agents_user_tool_result_event_params.py +44 -0
- arkruntime/types/session/plain_text_document_source.py +27 -0
- arkruntime/types/session/search_result_citations.py +20 -0
- arkruntime/types/session/search_result_content.py +20 -0
- arkruntime/types/session/send_session_events_request.py +24 -0
- arkruntime/types/session/send_session_events_response.py +22 -0
- arkruntime/types/session/session.py +80 -0
- arkruntime/types/session/session_resource.py +70 -0
- arkruntime/types/session/session_resource_access.py +18 -0
- arkruntime/types/session/session_resource_type.py +19 -0
- arkruntime/types/session/session_status.py +20 -0
- arkruntime/types/session/session_stream_shim.py +540 -0
- arkruntime/types/session/session_thread.py +56 -0
- arkruntime/types/session/session_thread_status.py +20 -0
- arkruntime/types/session/session_usage.py +36 -0
- arkruntime/types/session/tag.py +26 -0
- arkruntime/types/session/tool_confirmation_result.py +18 -0
- arkruntime/types/session/update_session_request.py +28 -0
- arkruntime/types/session/url_document_source.py +23 -0
- arkruntime/types/session/url_image_source.py +23 -0
- arkruntime/types/skill/__init__.py +18 -0
- arkruntime/types/skill/_init_extras_shim.py +12 -0
- arkruntime/types/skill/create_skill_request.py +18 -0
- arkruntime/types/skill/skill.py +46 -0
- arkruntime/types/tokenization/__init__.py +24 -0
- arkruntime/types/tokenization/_init_extras_shim.py +12 -0
- arkruntime/types/tokenization/tokenization_input.py +17 -0
- arkruntime/types/tokenization/tokenization_input_param.py +15 -0
- arkruntime/types/tokenization/tokenization_item.py +39 -0
- arkruntime/types/tokenization/tokenization_request.py +30 -0
- arkruntime/types/tokenization/tokenization_request_param.py +30 -0
- arkruntime/types/tokenization/tokenization_response.py +36 -0
- arkruntime/types/vault/__init__.py +62 -0
- arkruntime/types/vault/_init_extras_shim.py +12 -0
- arkruntime/types/vault/create_credential_request.py +32 -0
- arkruntime/types/vault/create_vault_request.py +26 -0
- arkruntime/types/vault/credential.py +52 -0
- arkruntime/types/vault/credential_auth.py +64 -0
- arkruntime/types/vault/credential_auth_type.py +22 -0
- arkruntime/types/vault/credential_networking.py +29 -0
- arkruntime/types/vault/credential_networking_type.py +18 -0
- arkruntime/types/vault/credential_validation.py +54 -0
- arkruntime/types/vault/delete_credential_response.py +26 -0
- arkruntime/types/vault/delete_vault_response.py +26 -0
- arkruntime/types/vault/limited_credential_networking.py +22 -0
- arkruntime/types/vault/list_credentials_response.py +35 -0
- arkruntime/types/vault/list_vaults_response.py +32 -0
- arkruntime/types/vault/mcp_probe.py +26 -0
- arkruntime/types/vault/mcpo_auth_refresh.py +45 -0
- arkruntime/types/vault/refresh_http_response.py +32 -0
- arkruntime/types/vault/refresh_object.py +27 -0
- arkruntime/types/vault/refresh_status.py +20 -0
- arkruntime/types/vault/token_endpoint_auth.py +29 -0
- arkruntime/types/vault/token_endpoint_auth_type.py +19 -0
- arkruntime/types/vault/update_credential_request.py +35 -0
- arkruntime/types/vault/update_vault_request.py +27 -0
- arkruntime/types/vault/validation_status.py +19 -0
- arkruntime/types/vault/vault.py +42 -0
- arkruntime-0.1.0.dist-info/METADATA +347 -0
- arkruntime-0.1.0.dist-info/RECORD +714 -0
- arkruntime-0.1.0.dist-info/WHEEL +5 -0
- arkruntime-0.1.0.dist-info/licenses/LICENSE +201 -0
- arkruntime-0.1.0.dist-info/top_level.txt +1 -0
arkruntime/_response.py
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
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 datetime
|
|
8
|
+
import functools
|
|
9
|
+
import inspect
|
|
10
|
+
import logging
|
|
11
|
+
from types import TracebackType
|
|
12
|
+
from typing import (
|
|
13
|
+
TYPE_CHECKING,
|
|
14
|
+
Any,
|
|
15
|
+
AsyncIterator,
|
|
16
|
+
Awaitable,
|
|
17
|
+
Callable,
|
|
18
|
+
Generic,
|
|
19
|
+
Iterator,
|
|
20
|
+
TypeVar,
|
|
21
|
+
Union,
|
|
22
|
+
cast,
|
|
23
|
+
overload,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
import httpx
|
|
27
|
+
import pydantic
|
|
28
|
+
from typing_extensions import ParamSpec, get_origin, override
|
|
29
|
+
|
|
30
|
+
from ._constants import CLIENT_REQUEST_HEADER, RAW_RESPONSE_HEADER # type: ignore
|
|
31
|
+
from ._exceptions import ArkError
|
|
32
|
+
from ._models import BaseModel, add_request_id, is_basemodel
|
|
33
|
+
from ._streaming import (
|
|
34
|
+
AsyncStream,
|
|
35
|
+
Stream,
|
|
36
|
+
extract_stream_chunk_type,
|
|
37
|
+
is_stream_class_type,
|
|
38
|
+
)
|
|
39
|
+
from ._types import NoneType
|
|
40
|
+
from ._utils import extract_type_arg, is_annotated_type, is_given, is_type_alias_type
|
|
41
|
+
|
|
42
|
+
if TYPE_CHECKING:
|
|
43
|
+
from ._base_client import BaseClient
|
|
44
|
+
from ._request_options import RequestOptions
|
|
45
|
+
|
|
46
|
+
P = ParamSpec("P")
|
|
47
|
+
R = TypeVar("R")
|
|
48
|
+
_T = TypeVar("_T")
|
|
49
|
+
_APIResponseT = TypeVar("_APIResponseT", bound="ArkAPIResponse[Any]")
|
|
50
|
+
_AsyncAPIResponseT = TypeVar("_AsyncAPIResponseT", bound="ArkAsyncAPIResponse[Any]")
|
|
51
|
+
_DefaultStreamT = TypeVar("_DefaultStreamT", bound=Union[Stream[Any], AsyncStream[Any]])
|
|
52
|
+
|
|
53
|
+
log: logging.Logger = logging.getLogger(__name__)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BaseAPIResponse(Generic[R]):
|
|
57
|
+
_cast_to: type[R]
|
|
58
|
+
_client: BaseClient
|
|
59
|
+
_parsed_by_type: dict[type[Any], Any]
|
|
60
|
+
_is_sse_stream: bool
|
|
61
|
+
_stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None
|
|
62
|
+
_request_id: str
|
|
63
|
+
_options: RequestOptions
|
|
64
|
+
|
|
65
|
+
http_response: httpx.Response
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
*,
|
|
70
|
+
raw: httpx.Response,
|
|
71
|
+
cast_to: type[R],
|
|
72
|
+
client: BaseClient,
|
|
73
|
+
stream: bool,
|
|
74
|
+
stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None,
|
|
75
|
+
options: RequestOptions,
|
|
76
|
+
) -> None:
|
|
77
|
+
self._cast_to = cast_to
|
|
78
|
+
self._client = client
|
|
79
|
+
self._parsed_by_type = {}
|
|
80
|
+
self._is_sse_stream = stream
|
|
81
|
+
self._stream_cls = stream_cls
|
|
82
|
+
self.http_response = raw
|
|
83
|
+
self._options = options
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def request_id(self) -> str:
|
|
87
|
+
return self.http_response.headers.get(CLIENT_REQUEST_HEADER)
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def headers(self) -> httpx.Headers:
|
|
91
|
+
return self.http_response.headers
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def http_request(self) -> httpx.Request:
|
|
95
|
+
return self.http_response.request
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def status_code(self) -> int:
|
|
99
|
+
return self.http_response.status_code
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def url(self) -> httpx.URL:
|
|
103
|
+
return self.http_response.url
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def method(self) -> str:
|
|
107
|
+
return self.http_request.method
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def http_version(self) -> str:
|
|
111
|
+
return self.http_response.http_version
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def elapsed(self) -> datetime.timedelta:
|
|
115
|
+
return self.http_response.elapsed
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def is_closed(self) -> bool:
|
|
119
|
+
return self.http_response.is_closed
|
|
120
|
+
|
|
121
|
+
@override
|
|
122
|
+
def __repr__(self) -> str:
|
|
123
|
+
return (
|
|
124
|
+
f"<{self.__class__.__name__} [{self.status_code} {self.http_response.reason_phrase}] type={self._cast_to}>"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def _parse(self, *, to: type[_T] | None = None) -> R | _T:
|
|
128
|
+
cast_to = to if to is not None else self._cast_to
|
|
129
|
+
|
|
130
|
+
# unwrap `TypeAlias('Name', T)` -> `T`
|
|
131
|
+
if is_type_alias_type(cast_to):
|
|
132
|
+
cast_to = cast_to.__value__ # type: ignore[unreachable]
|
|
133
|
+
|
|
134
|
+
# unwrap `Annotated[T, ...]` -> `T`
|
|
135
|
+
if cast_to and is_annotated_type(cast_to):
|
|
136
|
+
cast_to = extract_type_arg(cast_to, 0)
|
|
137
|
+
|
|
138
|
+
origin = get_origin(cast_to) or cast_to
|
|
139
|
+
|
|
140
|
+
if self._is_sse_stream:
|
|
141
|
+
if to:
|
|
142
|
+
if not is_stream_class_type(to):
|
|
143
|
+
raise TypeError(f"Expected custom parse type to be a subclass of {Stream} or {AsyncStream}")
|
|
144
|
+
|
|
145
|
+
return cast(
|
|
146
|
+
_T,
|
|
147
|
+
to(
|
|
148
|
+
cast_to=extract_stream_chunk_type(
|
|
149
|
+
to,
|
|
150
|
+
failure_message="Expected custom stream type to be passed with a type argument, e.g. Stream[ChunkType]",
|
|
151
|
+
),
|
|
152
|
+
response=self.http_response,
|
|
153
|
+
client=cast(Any, self._client),
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
if self._stream_cls:
|
|
158
|
+
return cast(
|
|
159
|
+
R,
|
|
160
|
+
self._stream_cls(
|
|
161
|
+
cast_to=extract_stream_chunk_type(self._stream_cls),
|
|
162
|
+
response=self.http_response,
|
|
163
|
+
client=cast(Any, self._client),
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
stream_cls = cast(
|
|
168
|
+
"type[Stream[Any]] | type[AsyncStream[Any]] | None",
|
|
169
|
+
self._client._default_stream_cls,
|
|
170
|
+
)
|
|
171
|
+
if stream_cls is None:
|
|
172
|
+
raise MissingStreamClassError()
|
|
173
|
+
|
|
174
|
+
return cast(
|
|
175
|
+
R,
|
|
176
|
+
stream_cls(
|
|
177
|
+
cast_to=cast_to,
|
|
178
|
+
response=self.http_response,
|
|
179
|
+
client=cast(Any, self._client),
|
|
180
|
+
),
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
if cast_to is NoneType:
|
|
184
|
+
return cast(R, None)
|
|
185
|
+
|
|
186
|
+
response = self.http_response
|
|
187
|
+
if cast_to == str:
|
|
188
|
+
return cast(R, response.text)
|
|
189
|
+
|
|
190
|
+
if cast_to == bytes:
|
|
191
|
+
return cast(R, response.content)
|
|
192
|
+
|
|
193
|
+
if cast_to == int:
|
|
194
|
+
return cast(R, int(response.text))
|
|
195
|
+
|
|
196
|
+
if cast_to == float:
|
|
197
|
+
return cast(R, float(response.text))
|
|
198
|
+
|
|
199
|
+
if cast_to == bool:
|
|
200
|
+
return cast(R, response.text.lower() == "true")
|
|
201
|
+
|
|
202
|
+
# handle the legacy binary response case
|
|
203
|
+
if inspect.isclass(cast_to) and cast_to.__name__ == "HttpxBinaryResponseContent":
|
|
204
|
+
return cast(R, cast_to(response)) # type: ignore
|
|
205
|
+
|
|
206
|
+
if origin == ArkAPIResponse:
|
|
207
|
+
raise RuntimeError("Unexpected state - cast_to is `APIResponse`")
|
|
208
|
+
|
|
209
|
+
if inspect.isclass(origin) and issubclass(origin, httpx.Response):
|
|
210
|
+
# Because of the invariance of our ResponseT TypeVar, users can subclass httpx.Response
|
|
211
|
+
# and pass that class to our request functions. We cannot change the variance to be either
|
|
212
|
+
# covariant or contravariant as that makes our usage of ResponseT illegal. We could construct
|
|
213
|
+
# the response class ourselves but that is something that should be supported directly in httpx
|
|
214
|
+
# as it would be easy to incorrectly construct the Response object due to the multitude of arguments.
|
|
215
|
+
if cast_to != httpx.Response:
|
|
216
|
+
raise ValueError("Subclasses of httpx.Response cannot be passed to `cast_to`")
|
|
217
|
+
return cast(R, response)
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
inspect.isclass(
|
|
221
|
+
origin # pyright: ignore[reportUnknownArgumentType]
|
|
222
|
+
)
|
|
223
|
+
and not issubclass(origin, BaseModel)
|
|
224
|
+
and issubclass(origin, pydantic.BaseModel)
|
|
225
|
+
):
|
|
226
|
+
raise TypeError("Pydantic models must subclass our base model type")
|
|
227
|
+
|
|
228
|
+
if (
|
|
229
|
+
cast_to is not object
|
|
230
|
+
and origin is not list
|
|
231
|
+
and origin is not dict
|
|
232
|
+
and origin is not Union
|
|
233
|
+
and not issubclass(origin, BaseModel)
|
|
234
|
+
):
|
|
235
|
+
raise RuntimeError(
|
|
236
|
+
f"Unsupported type, expected {cast_to} to be a subclass of {BaseModel}, {dict}, {list}, {Union}, {NoneType}, {str} or {httpx.Response}."
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
# split is required to handle cases where additional information is included
|
|
240
|
+
# in the response, e.g. application/json; charset=utf-8
|
|
241
|
+
content_type, *_ = response.headers.get("content-type", "*").split(";")
|
|
242
|
+
if content_type != "application/json":
|
|
243
|
+
if is_basemodel(cast_to):
|
|
244
|
+
try:
|
|
245
|
+
data = response.json()
|
|
246
|
+
except Exception as exc:
|
|
247
|
+
log.debug(
|
|
248
|
+
"Could not read JSON from response data due to %s - %s",
|
|
249
|
+
type(exc),
|
|
250
|
+
exc,
|
|
251
|
+
)
|
|
252
|
+
else:
|
|
253
|
+
return self._client._process_response_data(
|
|
254
|
+
data=data,
|
|
255
|
+
cast_to=cast_to, # type: ignore
|
|
256
|
+
response=response,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
# If the API responds with content that isn't JSON then we just return
|
|
260
|
+
# the (decoded) text without performing any parsing so that you can still
|
|
261
|
+
# handle the response however you need to.
|
|
262
|
+
return response.text # type: ignore
|
|
263
|
+
|
|
264
|
+
data = response.json()
|
|
265
|
+
|
|
266
|
+
return self._client._process_response_data(
|
|
267
|
+
data=data,
|
|
268
|
+
cast_to=cast_to, # type: ignore
|
|
269
|
+
response=response,
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class ArkAPIResponse(BaseAPIResponse[R]):
|
|
274
|
+
@property
|
|
275
|
+
def request_id(self) -> str:
|
|
276
|
+
return self.http_response.headers.get(CLIENT_REQUEST_HEADER, "")
|
|
277
|
+
|
|
278
|
+
def parse(self, *, to: type[_T] | None = None) -> R | _T:
|
|
279
|
+
"""Returns the rich python representation of this response's data.
|
|
280
|
+
|
|
281
|
+
For lower-level control, see `.read()`, `.json()`, `.iter_bytes()`.
|
|
282
|
+
|
|
283
|
+
You can customise the type that the response is parsed into through
|
|
284
|
+
the `to` argument, e.g.
|
|
285
|
+
|
|
286
|
+
```py
|
|
287
|
+
class MyModel(BaseModel):
|
|
288
|
+
foo: str
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
obj = response.parse(to=MyModel)
|
|
292
|
+
print(obj.foo)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
We support parsing:
|
|
296
|
+
- `BaseModel`
|
|
297
|
+
- `dict`
|
|
298
|
+
- `list`
|
|
299
|
+
- `Union`
|
|
300
|
+
- `str`
|
|
301
|
+
- `int`
|
|
302
|
+
- `float`
|
|
303
|
+
- `httpx.Response`
|
|
304
|
+
"""
|
|
305
|
+
cache_key = to if to is not None else self._cast_to
|
|
306
|
+
cached = self._parsed_by_type.get(cache_key)
|
|
307
|
+
if cached is not None:
|
|
308
|
+
return cached # type: ignore[no-any-return]
|
|
309
|
+
|
|
310
|
+
if not self._is_sse_stream:
|
|
311
|
+
self.read()
|
|
312
|
+
|
|
313
|
+
parsed = self._parse(to=to)
|
|
314
|
+
if is_given(self._options.post_parser):
|
|
315
|
+
parsed = self._options.post_parser(parsed)
|
|
316
|
+
|
|
317
|
+
if isinstance(parsed, BaseModel):
|
|
318
|
+
add_request_id(parsed, self.request_id)
|
|
319
|
+
|
|
320
|
+
self._parsed_by_type[cache_key] = parsed
|
|
321
|
+
return cast(R, parsed)
|
|
322
|
+
|
|
323
|
+
def read(self) -> bytes:
|
|
324
|
+
try:
|
|
325
|
+
return self.http_response.read()
|
|
326
|
+
except httpx.StreamConsumed as exc:
|
|
327
|
+
raise StreamAlreadyConsumed() from exc
|
|
328
|
+
|
|
329
|
+
def text(self) -> str:
|
|
330
|
+
self.read()
|
|
331
|
+
return self.http_response.text
|
|
332
|
+
|
|
333
|
+
def json(self) -> object:
|
|
334
|
+
self.read()
|
|
335
|
+
return self.http_response.json()
|
|
336
|
+
|
|
337
|
+
def close(self) -> None:
|
|
338
|
+
self.http_response.close()
|
|
339
|
+
|
|
340
|
+
def iter_bytes(self, chunk_size: int | None = None) -> Iterator[bytes]:
|
|
341
|
+
for chunk in self.http_response.iter_bytes(chunk_size):
|
|
342
|
+
yield chunk
|
|
343
|
+
|
|
344
|
+
def iter_text(self, chunk_size: int | None = None) -> Iterator[str]:
|
|
345
|
+
for chunk in self.http_response.iter_text(chunk_size):
|
|
346
|
+
yield chunk
|
|
347
|
+
|
|
348
|
+
def iter_lines(self) -> Iterator[str]:
|
|
349
|
+
for chunk in self.http_response.iter_lines():
|
|
350
|
+
yield chunk
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
class ArkAsyncAPIResponse(BaseAPIResponse[R]):
|
|
354
|
+
@property
|
|
355
|
+
def request_id(self) -> str:
|
|
356
|
+
return self.http_response.headers.get(CLIENT_REQUEST_HEADER, "")
|
|
357
|
+
|
|
358
|
+
@overload
|
|
359
|
+
async def parse(self, *, to: type[_T]) -> _T: ...
|
|
360
|
+
|
|
361
|
+
@overload
|
|
362
|
+
async def parse(self) -> R: ...
|
|
363
|
+
|
|
364
|
+
async def parse(self, *, to: type[_T] | None = None) -> R | _T:
|
|
365
|
+
"""Returns the rich python representation of this response's data.
|
|
366
|
+
|
|
367
|
+
For lower-level control, see `.read()`, `.json()`, `.iter_bytes()`.
|
|
368
|
+
|
|
369
|
+
You can customise the type that the response is parsed into through
|
|
370
|
+
the `to` argument, e.g.
|
|
371
|
+
|
|
372
|
+
```py
|
|
373
|
+
class MyModel(BaseModel):
|
|
374
|
+
foo: str
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
obj = response.parse(to=MyModel)
|
|
378
|
+
print(obj.foo)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
We support parsing:
|
|
382
|
+
- `BaseModel`
|
|
383
|
+
- `dict`
|
|
384
|
+
- `list`
|
|
385
|
+
- `Union`
|
|
386
|
+
- `str`
|
|
387
|
+
- `httpx.Response`
|
|
388
|
+
"""
|
|
389
|
+
cache_key = to if to is not None else self._cast_to
|
|
390
|
+
cached = self._parsed_by_type.get(cache_key)
|
|
391
|
+
if cached is not None:
|
|
392
|
+
return cached # type: ignore[no-any-return]
|
|
393
|
+
|
|
394
|
+
if not self._is_sse_stream:
|
|
395
|
+
await self.read()
|
|
396
|
+
|
|
397
|
+
parsed = self._parse(to=to)
|
|
398
|
+
if is_given(self._options.post_parser):
|
|
399
|
+
parsed = self._options.post_parser(parsed)
|
|
400
|
+
|
|
401
|
+
if isinstance(parsed, BaseModel):
|
|
402
|
+
add_request_id(parsed, self.request_id)
|
|
403
|
+
|
|
404
|
+
self._parsed_by_type[cache_key] = parsed
|
|
405
|
+
return cast(R, parsed)
|
|
406
|
+
|
|
407
|
+
async def read(self) -> bytes:
|
|
408
|
+
"""Read and return the binary response content."""
|
|
409
|
+
try:
|
|
410
|
+
return await self.http_response.aread()
|
|
411
|
+
except httpx.StreamConsumed as exc:
|
|
412
|
+
# the default error raised by httpx isn't very
|
|
413
|
+
# helpful in our case so we re-raise it with
|
|
414
|
+
# a different error message
|
|
415
|
+
raise StreamAlreadyConsumed() from exc
|
|
416
|
+
|
|
417
|
+
async def text(self) -> str:
|
|
418
|
+
"""Read and decode the response content into a string."""
|
|
419
|
+
await self.read()
|
|
420
|
+
return self.http_response.text
|
|
421
|
+
|
|
422
|
+
async def json(self) -> object:
|
|
423
|
+
"""Read and decode the JSON response content."""
|
|
424
|
+
await self.read()
|
|
425
|
+
return self.http_response.json()
|
|
426
|
+
|
|
427
|
+
async def close(self) -> None:
|
|
428
|
+
"""Close the response and release the connection.
|
|
429
|
+
|
|
430
|
+
Automatically called if the response body is read to completion.
|
|
431
|
+
"""
|
|
432
|
+
await self.http_response.aclose()
|
|
433
|
+
|
|
434
|
+
async def iter_bytes(self, chunk_size: int | None = None) -> AsyncIterator[bytes]:
|
|
435
|
+
"""
|
|
436
|
+
A byte-iterator over the decoded response content.
|
|
437
|
+
|
|
438
|
+
This automatically handles gzip, deflate and brotli encoded responses.
|
|
439
|
+
"""
|
|
440
|
+
async for chunk in self.http_response.aiter_bytes(chunk_size):
|
|
441
|
+
yield chunk
|
|
442
|
+
|
|
443
|
+
async def iter_text(self, chunk_size: int | None = None) -> AsyncIterator[str]:
|
|
444
|
+
"""A str-iterator over the decoded response content
|
|
445
|
+
that handles both gzip, deflate, etc but also detects the content's
|
|
446
|
+
string encoding.
|
|
447
|
+
"""
|
|
448
|
+
async for chunk in self.http_response.aiter_text(chunk_size):
|
|
449
|
+
yield chunk
|
|
450
|
+
|
|
451
|
+
async def iter_lines(self) -> AsyncIterator[str]:
|
|
452
|
+
"""Like `iter_text()` but will only yield chunks for each line"""
|
|
453
|
+
async for chunk in self.http_response.aiter_lines():
|
|
454
|
+
yield chunk
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
class MissingStreamClassError(TypeError):
|
|
458
|
+
def __init__(self) -> None:
|
|
459
|
+
super().__init__("The `stream` argument was set to `True` but the `stream_cls` argument was not given.")
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
class StreamAlreadyConsumed(ArkError):
|
|
463
|
+
def __init__(self) -> None:
|
|
464
|
+
message = (
|
|
465
|
+
"Attempted to read or stream some content, but the content has "
|
|
466
|
+
"already been streamed. "
|
|
467
|
+
"This could be due to attempting to stream the response "
|
|
468
|
+
"content more than once."
|
|
469
|
+
"\n\n"
|
|
470
|
+
"You can fix this by manually accumulating the response content while streaming "
|
|
471
|
+
"or by calling `.read()` before starting to stream."
|
|
472
|
+
)
|
|
473
|
+
super().__init__(message)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def to_raw_response_wrapper(func: Callable[P, R]) -> Callable[P, ArkAPIResponse[R]]:
|
|
477
|
+
"""Higher order function that takes one of our bound API methods and wraps it
|
|
478
|
+
to support returning the raw `APIResponse` object directly.
|
|
479
|
+
"""
|
|
480
|
+
|
|
481
|
+
@functools.wraps(func)
|
|
482
|
+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> ArkAPIResponse[R]:
|
|
483
|
+
extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
|
|
484
|
+
extra_headers[RAW_RESPONSE_HEADER] = "raw"
|
|
485
|
+
|
|
486
|
+
kwargs["extra_headers"] = extra_headers
|
|
487
|
+
|
|
488
|
+
return cast(ArkAPIResponse[R], func(*args, **kwargs))
|
|
489
|
+
|
|
490
|
+
return wrapped
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def async_to_raw_response_wrapper(
|
|
494
|
+
func: Callable[P, Awaitable[R]],
|
|
495
|
+
) -> Callable[P, Awaitable[ArkAsyncAPIResponse[R]]]:
|
|
496
|
+
"""Higher order function that takes one of our bound API methods and wraps it
|
|
497
|
+
to support returning the raw `APIResponse` object directly.
|
|
498
|
+
"""
|
|
499
|
+
|
|
500
|
+
@functools.wraps(func)
|
|
501
|
+
async def wrapped(*args: P.args, **kwargs: P.kwargs) -> ArkAsyncAPIResponse[R]:
|
|
502
|
+
extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
|
|
503
|
+
extra_headers[RAW_RESPONSE_HEADER] = "raw"
|
|
504
|
+
|
|
505
|
+
kwargs["extra_headers"] = extra_headers
|
|
506
|
+
|
|
507
|
+
return cast(ArkAsyncAPIResponse[R], await func(*args, **kwargs))
|
|
508
|
+
|
|
509
|
+
return wrapped
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def to_streamed_response_wrapper(
|
|
513
|
+
func: Callable[P, R],
|
|
514
|
+
) -> Callable[P, ResponseContextManager[ArkAPIResponse[R]]]:
|
|
515
|
+
"""Higher order function that takes one of our bound API methods and wraps it
|
|
516
|
+
to support streaming and returning the raw `APIResponse` object directly.
|
|
517
|
+
"""
|
|
518
|
+
|
|
519
|
+
@functools.wraps(func)
|
|
520
|
+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> ResponseContextManager[ArkAPIResponse[R]]:
|
|
521
|
+
extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
|
|
522
|
+
extra_headers[RAW_RESPONSE_HEADER] = "stream"
|
|
523
|
+
|
|
524
|
+
kwargs["extra_headers"] = extra_headers
|
|
525
|
+
|
|
526
|
+
make_request = functools.partial(func, *args, **kwargs)
|
|
527
|
+
|
|
528
|
+
return ResponseContextManager(cast(Callable[[], ArkAPIResponse[R]], make_request))
|
|
529
|
+
|
|
530
|
+
return wrapped
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
def async_to_streamed_response_wrapper(
|
|
534
|
+
func: Callable[P, Awaitable[R]],
|
|
535
|
+
) -> Callable[P, AsyncResponseContextManager[ArkAsyncAPIResponse[R]]]:
|
|
536
|
+
"""Higher order function that takes one of our bound API methods and wraps it
|
|
537
|
+
to support streaming and returning the raw `APIResponse` object directly.
|
|
538
|
+
"""
|
|
539
|
+
|
|
540
|
+
@functools.wraps(func)
|
|
541
|
+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> AsyncResponseContextManager[ArkAsyncAPIResponse[R]]:
|
|
542
|
+
extra_headers: dict[str, str] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
|
|
543
|
+
extra_headers[RAW_RESPONSE_HEADER] = "stream"
|
|
544
|
+
|
|
545
|
+
kwargs["extra_headers"] = extra_headers
|
|
546
|
+
|
|
547
|
+
make_request = func(*args, **kwargs)
|
|
548
|
+
|
|
549
|
+
return AsyncResponseContextManager(cast(Awaitable[ArkAsyncAPIResponse[R]], make_request))
|
|
550
|
+
|
|
551
|
+
return wrapped
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
class ResponseContextManager(Generic[_APIResponseT]):
|
|
555
|
+
"""Context manager for ensuring that a request is not made
|
|
556
|
+
until it is entered and that the response will always be closed
|
|
557
|
+
when the context manager exits
|
|
558
|
+
"""
|
|
559
|
+
|
|
560
|
+
def __init__(self, request_func: Callable[[], _APIResponseT]) -> None:
|
|
561
|
+
self._request_func = request_func
|
|
562
|
+
self.__response: _APIResponseT | None = None
|
|
563
|
+
|
|
564
|
+
def __enter__(self) -> _APIResponseT:
|
|
565
|
+
self.__response = self._request_func()
|
|
566
|
+
return self.__response
|
|
567
|
+
|
|
568
|
+
def __exit__(
|
|
569
|
+
self,
|
|
570
|
+
exc_type: type[BaseException] | None,
|
|
571
|
+
exc: BaseException | None,
|
|
572
|
+
exc_tb: TracebackType | None,
|
|
573
|
+
) -> None:
|
|
574
|
+
if self.__response is not None:
|
|
575
|
+
self.__response.close()
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
class AsyncResponseContextManager(Generic[_AsyncAPIResponseT]):
|
|
579
|
+
"""Context manager for ensuring that a request is not made
|
|
580
|
+
until it is entered and that the response will always be closed
|
|
581
|
+
when the context manager exits
|
|
582
|
+
"""
|
|
583
|
+
|
|
584
|
+
def __init__(self, api_request: Awaitable[_AsyncAPIResponseT]) -> None:
|
|
585
|
+
self._api_request = api_request
|
|
586
|
+
self.__response: _AsyncAPIResponseT | None = None
|
|
587
|
+
|
|
588
|
+
async def __aenter__(self) -> _AsyncAPIResponseT:
|
|
589
|
+
self.__response = await self._api_request
|
|
590
|
+
return self.__response
|
|
591
|
+
|
|
592
|
+
async def __aexit__(
|
|
593
|
+
self,
|
|
594
|
+
exc_type: type[BaseException] | None,
|
|
595
|
+
exc: BaseException | None,
|
|
596
|
+
exc_tb: TracebackType | None,
|
|
597
|
+
) -> None:
|
|
598
|
+
if self.__response is not None:
|
|
599
|
+
await self.__response.close()
|