mirascope 2.0.0a5__py3-none-any.whl → 2.0.1__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 (349) hide show
  1. mirascope/__init__.py +10 -1
  2. mirascope/_stubs.py +363 -0
  3. mirascope/api/__init__.py +8 -0
  4. mirascope/api/_generated/__init__.py +285 -2
  5. mirascope/api/_generated/annotations/__init__.py +33 -0
  6. mirascope/api/_generated/annotations/client.py +506 -0
  7. mirascope/api/_generated/annotations/raw_client.py +1414 -0
  8. mirascope/api/_generated/annotations/types/__init__.py +31 -0
  9. mirascope/api/_generated/annotations/types/annotations_create_request_label.py +5 -0
  10. mirascope/api/_generated/annotations/types/annotations_create_response.py +48 -0
  11. mirascope/api/_generated/annotations/types/annotations_create_response_label.py +5 -0
  12. mirascope/api/_generated/annotations/types/annotations_get_response.py +48 -0
  13. mirascope/api/_generated/annotations/types/annotations_get_response_label.py +5 -0
  14. mirascope/api/_generated/annotations/types/annotations_list_request_label.py +5 -0
  15. mirascope/api/_generated/annotations/types/annotations_list_response.py +21 -0
  16. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +50 -0
  17. mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item_label.py +5 -0
  18. mirascope/api/_generated/annotations/types/annotations_update_request_label.py +5 -0
  19. mirascope/api/_generated/annotations/types/annotations_update_response.py +48 -0
  20. mirascope/api/_generated/annotations/types/annotations_update_response_label.py +5 -0
  21. mirascope/api/_generated/api_keys/__init__.py +12 -2
  22. mirascope/api/_generated/api_keys/client.py +77 -0
  23. mirascope/api/_generated/api_keys/raw_client.py +422 -39
  24. mirascope/api/_generated/api_keys/types/__init__.py +7 -1
  25. mirascope/api/_generated/api_keys/types/api_keys_create_response.py +4 -12
  26. mirascope/api/_generated/api_keys/types/api_keys_get_response.py +4 -12
  27. mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
  28. mirascope/api/_generated/api_keys/types/api_keys_list_response_item.py +4 -12
  29. mirascope/api/_generated/client.py +42 -0
  30. mirascope/api/_generated/core/client_wrapper.py +2 -14
  31. mirascope/api/_generated/core/datetime_utils.py +1 -3
  32. mirascope/api/_generated/core/file.py +2 -5
  33. mirascope/api/_generated/core/http_client.py +36 -112
  34. mirascope/api/_generated/core/jsonable_encoder.py +1 -3
  35. mirascope/api/_generated/core/pydantic_utilities.py +19 -74
  36. mirascope/api/_generated/core/query_encoder.py +1 -3
  37. mirascope/api/_generated/core/serialization.py +4 -10
  38. mirascope/api/_generated/docs/client.py +2 -6
  39. mirascope/api/_generated/docs/raw_client.py +51 -5
  40. mirascope/api/_generated/environment.py +3 -3
  41. mirascope/api/_generated/environments/__init__.py +6 -0
  42. mirascope/api/_generated/environments/client.py +117 -0
  43. mirascope/api/_generated/environments/raw_client.py +530 -51
  44. mirascope/api/_generated/environments/types/__init__.py +10 -0
  45. mirascope/api/_generated/environments/types/environments_create_response.py +1 -3
  46. mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
  47. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
  48. mirascope/api/_generated/environments/types/environments_get_analytics_response_top_models_item.py +22 -0
  49. mirascope/api/_generated/environments/types/environments_get_response.py +1 -3
  50. mirascope/api/_generated/environments/types/environments_list_response_item.py +1 -3
  51. mirascope/api/_generated/environments/types/environments_update_response.py +1 -3
  52. mirascope/api/_generated/errors/__init__.py +8 -0
  53. mirascope/api/_generated/errors/bad_request_error.py +1 -2
  54. mirascope/api/_generated/errors/conflict_error.py +1 -2
  55. mirascope/api/_generated/errors/forbidden_error.py +1 -5
  56. mirascope/api/_generated/errors/internal_server_error.py +1 -6
  57. mirascope/api/_generated/errors/not_found_error.py +1 -5
  58. mirascope/api/_generated/errors/payment_required_error.py +15 -0
  59. mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
  60. mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
  61. mirascope/api/_generated/errors/unauthorized_error.py +11 -0
  62. mirascope/api/_generated/functions/__init__.py +39 -0
  63. mirascope/api/_generated/functions/client.py +647 -0
  64. mirascope/api/_generated/functions/raw_client.py +1890 -0
  65. mirascope/api/_generated/functions/types/__init__.py +53 -0
  66. mirascope/api/_generated/functions/types/functions_create_request_dependencies_value.py +20 -0
  67. mirascope/api/_generated/functions/types/functions_create_response.py +37 -0
  68. mirascope/api/_generated/functions/types/functions_create_response_dependencies_value.py +20 -0
  69. mirascope/api/_generated/functions/types/functions_find_by_hash_response.py +39 -0
  70. mirascope/api/_generated/functions/types/functions_find_by_hash_response_dependencies_value.py +20 -0
  71. mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
  72. mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
  73. mirascope/api/_generated/functions/types/functions_get_response.py +37 -0
  74. mirascope/api/_generated/functions/types/functions_get_response_dependencies_value.py +20 -0
  75. mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
  76. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
  77. mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
  78. mirascope/api/_generated/functions/types/functions_list_response.py +21 -0
  79. mirascope/api/_generated/functions/types/functions_list_response_functions_item.py +41 -0
  80. mirascope/api/_generated/functions/types/functions_list_response_functions_item_dependencies_value.py +20 -0
  81. mirascope/api/_generated/health/client.py +2 -6
  82. mirascope/api/_generated/health/raw_client.py +51 -5
  83. mirascope/api/_generated/health/types/health_check_response.py +1 -3
  84. mirascope/api/_generated/organization_invitations/__init__.py +33 -0
  85. mirascope/api/_generated/organization_invitations/client.py +546 -0
  86. mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
  87. mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
  88. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
  89. mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
  90. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
  91. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
  92. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
  93. mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
  94. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
  95. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
  96. mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
  97. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
  98. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
  99. mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
  100. mirascope/api/_generated/organization_memberships/__init__.py +19 -0
  101. mirascope/api/_generated/organization_memberships/client.py +302 -0
  102. mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
  103. mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
  104. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
  105. mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
  106. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
  107. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
  108. mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
  109. mirascope/api/_generated/organizations/__init__.py +26 -0
  110. mirascope/api/_generated/organizations/client.py +465 -0
  111. mirascope/api/_generated/organizations/raw_client.py +1799 -108
  112. mirascope/api/_generated/organizations/types/__init__.py +48 -0
  113. mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
  114. mirascope/api/_generated/organizations/types/organizations_create_response.py +4 -3
  115. mirascope/api/_generated/organizations/types/organizations_create_response_role.py +1 -3
  116. mirascope/api/_generated/organizations/types/organizations_get_response.py +4 -3
  117. mirascope/api/_generated/organizations/types/organizations_get_response_role.py +1 -3
  118. mirascope/api/_generated/organizations/types/organizations_list_response_item.py +4 -3
  119. mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +1 -3
  120. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
  121. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
  122. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
  123. mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
  124. mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
  125. mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
  126. mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
  127. mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
  128. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
  129. mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
  130. mirascope/api/_generated/organizations/types/organizations_update_response.py +4 -3
  131. mirascope/api/_generated/organizations/types/organizations_update_response_role.py +1 -3
  132. mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
  133. mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
  134. mirascope/api/_generated/project_memberships/__init__.py +25 -0
  135. mirascope/api/_generated/project_memberships/client.py +437 -0
  136. mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
  137. mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
  138. mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
  139. mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
  140. mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
  141. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
  142. mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
  143. mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
  144. mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
  145. mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
  146. mirascope/api/_generated/projects/__init__.py +2 -12
  147. mirascope/api/_generated/projects/client.py +17 -71
  148. mirascope/api/_generated/projects/raw_client.py +295 -51
  149. mirascope/api/_generated/projects/types/__init__.py +1 -6
  150. mirascope/api/_generated/projects/types/projects_create_response.py +3 -9
  151. mirascope/api/_generated/projects/types/projects_get_response.py +3 -9
  152. mirascope/api/_generated/projects/types/projects_list_response_item.py +3 -9
  153. mirascope/api/_generated/projects/types/projects_update_response.py +3 -9
  154. mirascope/api/_generated/reference.md +3619 -182
  155. mirascope/api/_generated/tags/__init__.py +19 -0
  156. mirascope/api/_generated/tags/client.py +504 -0
  157. mirascope/api/_generated/tags/raw_client.py +1288 -0
  158. mirascope/api/_generated/tags/types/__init__.py +17 -0
  159. mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
  160. mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
  161. mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
  162. mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
  163. mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
  164. mirascope/api/_generated/token_cost/__init__.py +7 -0
  165. mirascope/api/_generated/token_cost/client.py +160 -0
  166. mirascope/api/_generated/token_cost/raw_client.py +264 -0
  167. mirascope/api/_generated/token_cost/types/__init__.py +8 -0
  168. mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
  169. mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
  170. mirascope/api/_generated/traces/__init__.py +42 -0
  171. mirascope/api/_generated/traces/client.py +941 -0
  172. mirascope/api/_generated/traces/raw_client.py +2177 -23
  173. mirascope/api/_generated/traces/types/__init__.py +60 -0
  174. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +4 -11
  175. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +2 -6
  176. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +1 -3
  177. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +8 -24
  178. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +2 -6
  179. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +3 -9
  180. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +2 -6
  181. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +3 -9
  182. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +4 -8
  183. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +2 -6
  184. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +8 -24
  185. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +2 -6
  186. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +3 -9
  187. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +1 -3
  188. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +6 -18
  189. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +3 -9
  190. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +8 -24
  191. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +2 -6
  192. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +2 -6
  193. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +1 -3
  194. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +2 -6
  195. mirascope/api/_generated/traces/types/traces_create_response.py +2 -5
  196. mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +3 -9
  197. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +60 -0
  198. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_functions_item.py +24 -0
  199. mirascope/api/_generated/traces/types/traces_get_analytics_summary_response_top_models_item.py +22 -0
  200. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
  201. mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
  202. mirascope/api/_generated/traces/types/traces_get_trace_detail_response.py +33 -0
  203. mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +88 -0
  204. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
  205. mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
  206. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
  207. mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
  208. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
  209. mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
  210. mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
  211. mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
  212. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item.py +26 -0
  213. mirascope/api/_generated/traces/types/traces_search_request_attribute_filters_item_operator.py +7 -0
  214. mirascope/api/_generated/traces/types/traces_search_request_sort_by.py +7 -0
  215. mirascope/api/_generated/traces/types/traces_search_request_sort_order.py +5 -0
  216. mirascope/api/_generated/traces/types/traces_search_response.py +26 -0
  217. mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +50 -0
  218. mirascope/api/_generated/types/__init__.py +48 -0
  219. mirascope/api/_generated/types/already_exists_error.py +1 -3
  220. mirascope/api/_generated/types/bad_request_error_body.py +50 -0
  221. mirascope/api/_generated/types/click_house_error.py +22 -0
  222. mirascope/api/_generated/types/database_error.py +1 -3
  223. mirascope/api/_generated/types/date.py +3 -0
  224. mirascope/api/_generated/types/http_api_decode_error.py +1 -3
  225. mirascope/api/_generated/types/immutable_resource_error.py +22 -0
  226. mirascope/api/_generated/types/internal_server_error_body.py +49 -0
  227. mirascope/api/_generated/types/issue.py +1 -3
  228. mirascope/api/_generated/types/issue_tag.py +1 -8
  229. mirascope/api/_generated/types/not_found_error_body.py +1 -3
  230. mirascope/api/_generated/types/number_from_string.py +3 -0
  231. mirascope/api/_generated/types/permission_denied_error.py +1 -3
  232. mirascope/api/_generated/types/permission_denied_error_tag.py +1 -3
  233. mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
  234. mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
  235. mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
  236. mirascope/api/_generated/types/property_key_key.py +1 -3
  237. mirascope/api/_generated/types/rate_limit_error.py +31 -0
  238. mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
  239. mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
  240. mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
  241. mirascope/api/_generated/types/stripe_error.py +20 -0
  242. mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
  243. mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
  244. mirascope/api/_generated/types/unauthorized_error_body.py +21 -0
  245. mirascope/api/_generated/types/unauthorized_error_tag.py +5 -0
  246. mirascope/api/settings.py +19 -1
  247. mirascope/llm/__init__.py +55 -8
  248. mirascope/llm/calls/__init__.py +2 -1
  249. mirascope/llm/calls/calls.py +3 -1
  250. mirascope/llm/calls/decorator.py +21 -7
  251. mirascope/llm/content/tool_call.py +6 -0
  252. mirascope/llm/content/tool_output.py +22 -5
  253. mirascope/llm/exceptions.py +284 -71
  254. mirascope/llm/formatting/__init__.py +19 -2
  255. mirascope/llm/formatting/format.py +219 -30
  256. mirascope/llm/formatting/output_parser.py +178 -0
  257. mirascope/llm/formatting/partial.py +80 -7
  258. mirascope/llm/formatting/primitives.py +192 -0
  259. mirascope/llm/formatting/types.py +21 -64
  260. mirascope/llm/mcp/__init__.py +2 -2
  261. mirascope/llm/mcp/mcp_client.py +130 -0
  262. mirascope/llm/messages/__init__.py +3 -0
  263. mirascope/llm/messages/_utils.py +34 -0
  264. mirascope/llm/models/__init__.py +5 -0
  265. mirascope/llm/models/models.py +137 -69
  266. mirascope/llm/{providers/base → models}/params.py +16 -37
  267. mirascope/llm/models/thinking_config.py +61 -0
  268. mirascope/llm/prompts/_utils.py +0 -32
  269. mirascope/llm/prompts/decorator.py +16 -5
  270. mirascope/llm/prompts/prompts.py +131 -68
  271. mirascope/llm/providers/__init__.py +18 -2
  272. mirascope/llm/providers/anthropic/__init__.py +3 -21
  273. mirascope/llm/providers/anthropic/_utils/__init__.py +2 -0
  274. mirascope/llm/providers/anthropic/_utils/beta_decode.py +22 -11
  275. mirascope/llm/providers/anthropic/_utils/beta_encode.py +75 -25
  276. mirascope/llm/providers/anthropic/_utils/decode.py +22 -11
  277. mirascope/llm/providers/anthropic/_utils/encode.py +82 -20
  278. mirascope/llm/providers/anthropic/_utils/errors.py +2 -2
  279. mirascope/llm/providers/anthropic/beta_provider.py +64 -18
  280. mirascope/llm/providers/anthropic/provider.py +91 -33
  281. mirascope/llm/providers/base/__init__.py +0 -2
  282. mirascope/llm/providers/base/_utils.py +55 -11
  283. mirascope/llm/providers/base/base_provider.py +116 -37
  284. mirascope/llm/providers/google/__init__.py +2 -17
  285. mirascope/llm/providers/google/_utils/__init__.py +2 -0
  286. mirascope/llm/providers/google/_utils/decode.py +37 -15
  287. mirascope/llm/providers/google/_utils/encode.py +127 -19
  288. mirascope/llm/providers/google/_utils/errors.py +3 -2
  289. mirascope/llm/providers/google/model_info.py +1 -0
  290. mirascope/llm/providers/google/provider.py +68 -19
  291. mirascope/llm/providers/mirascope/__init__.py +5 -0
  292. mirascope/llm/providers/mirascope/_utils.py +73 -0
  293. mirascope/llm/providers/mirascope/provider.py +349 -0
  294. mirascope/llm/providers/mlx/__init__.py +2 -17
  295. mirascope/llm/providers/mlx/_utils.py +8 -3
  296. mirascope/llm/providers/mlx/encoding/base.py +5 -2
  297. mirascope/llm/providers/mlx/encoding/transformers.py +5 -2
  298. mirascope/llm/providers/mlx/mlx.py +23 -6
  299. mirascope/llm/providers/mlx/provider.py +42 -13
  300. mirascope/llm/providers/ollama/__init__.py +1 -13
  301. mirascope/llm/providers/openai/_utils/errors.py +2 -2
  302. mirascope/llm/providers/openai/completions/__init__.py +2 -20
  303. mirascope/llm/providers/openai/completions/_utils/decode.py +14 -3
  304. mirascope/llm/providers/openai/completions/_utils/encode.py +35 -28
  305. mirascope/llm/providers/openai/completions/base_provider.py +40 -11
  306. mirascope/llm/providers/openai/provider.py +40 -10
  307. mirascope/llm/providers/openai/responses/__init__.py +1 -17
  308. mirascope/llm/providers/openai/responses/_utils/__init__.py +2 -0
  309. mirascope/llm/providers/openai/responses/_utils/decode.py +21 -8
  310. mirascope/llm/providers/openai/responses/_utils/encode.py +59 -19
  311. mirascope/llm/providers/openai/responses/provider.py +56 -18
  312. mirascope/llm/providers/provider_id.py +1 -0
  313. mirascope/llm/providers/provider_registry.py +96 -19
  314. mirascope/llm/providers/together/__init__.py +1 -13
  315. mirascope/llm/responses/__init__.py +6 -1
  316. mirascope/llm/responses/_utils.py +102 -12
  317. mirascope/llm/responses/base_response.py +5 -2
  318. mirascope/llm/responses/base_stream_response.py +139 -45
  319. mirascope/llm/responses/response.py +2 -1
  320. mirascope/llm/responses/root_response.py +89 -17
  321. mirascope/llm/responses/stream_response.py +6 -9
  322. mirascope/llm/tools/decorator.py +17 -8
  323. mirascope/llm/tools/tool_schema.py +43 -10
  324. mirascope/llm/tools/toolkit.py +35 -27
  325. mirascope/llm/tools/tools.py +123 -30
  326. mirascope/ops/__init__.py +64 -109
  327. mirascope/ops/_internal/configuration.py +82 -31
  328. mirascope/ops/_internal/exporters/exporters.py +64 -11
  329. mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
  330. mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
  331. mirascope/ops/_internal/instrumentation/llm/encode.py +1 -1
  332. mirascope/ops/_internal/instrumentation/llm/llm.py +116 -1243
  333. mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
  334. mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
  335. mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
  336. mirascope/ops/_internal/protocols.py +83 -1
  337. mirascope/ops/_internal/traced_calls.py +4 -0
  338. mirascope/ops/_internal/traced_functions.py +141 -12
  339. mirascope/ops/_internal/tracing.py +78 -1
  340. mirascope/ops/_internal/utils.py +52 -4
  341. mirascope/ops/_internal/versioned_functions.py +54 -43
  342. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/METADATA +14 -13
  343. mirascope-2.0.1.dist-info/RECORD +423 -0
  344. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/licenses/LICENSE +1 -1
  345. mirascope/llm/formatting/_utils.py +0 -78
  346. mirascope/llm/mcp/client.py +0 -118
  347. mirascope/llm/providers/_missing_import_stubs.py +0 -49
  348. mirascope-2.0.0a5.dist-info/RECORD +0 -265
  349. {mirascope-2.0.0a5.dist-info → mirascope-2.0.1.dist-info}/WHEEL +0 -0
mirascope/__init__.py CHANGED
@@ -1,5 +1,14 @@
1
1
  """Mirascope v2 Beta."""
2
2
 
3
- from . import api as api, llm as llm, ops as ops
3
+ from contextlib import suppress
4
+
5
+ with suppress(ImportError):
6
+ from . import llm as llm
7
+
8
+ with suppress(ImportError):
9
+ from . import api as api
10
+
11
+ with suppress(ImportError):
12
+ from . import ops as ops
4
13
 
5
14
  __all__ = ["api", "llm", "ops"]
mirascope/_stubs.py ADDED
@@ -0,0 +1,363 @@
1
+ """Utilities for stubbing modules with missing optional dependencies."""
2
+
3
+ import sys
4
+ from collections.abc import MutableSequence
5
+ from importlib.abc import Loader, MetaPathFinder
6
+ from importlib.machinery import ModuleSpec
7
+ from types import ModuleType
8
+ from typing import Any
9
+
10
+ # ruff: noqa: ANN401
11
+
12
+ # Mapping of extra names to their import names
13
+ # This mapping is automatically generated from pyproject.toml
14
+ # To regenerate: uv run python scripts/generate_extra_imports.py --overwrite
15
+ # BEGIN GENERATED - DO NOT EDIT MANUALLY
16
+ EXTRA_IMPORTS: dict[str, list[str]] = {
17
+ "anthropic": ["anthropic"],
18
+ "api": ["pydantic_settings"],
19
+ "google": [
20
+ "google.genai",
21
+ "PIL",
22
+ "proto",
23
+ ],
24
+ "openai": ["openai"],
25
+ "mcp": ["mcp"],
26
+ "ops": [
27
+ "opentelemetry.sdk",
28
+ "opentelemetry",
29
+ "opentelemetry.instrumentation",
30
+ "opentelemetry.exporter.otlp",
31
+ "opentelemetry.propagators.b3",
32
+ "orjson",
33
+ "opentelemetry.propagators.jaeger",
34
+ "libcst",
35
+ "packaging",
36
+ ],
37
+ "mlx": ["mlx_lm"],
38
+ }
39
+ # END GENERATED
40
+
41
+
42
+ def _make_import_error(package_name: str, name: str) -> ImportError:
43
+ """Create an ImportError with a helpful installation message.
44
+
45
+ Args:
46
+ package_name: The package/extra name (e.g., "ops", "api")
47
+ name: The specific item being accessed (e.g., "trace", "settings")
48
+
49
+ Returns:
50
+ ImportError with installation instructions
51
+ """
52
+ return ImportError(
53
+ f"The '{package_name}' packages are required to use {name}. "
54
+ f"Install them with: `uv add 'mirascope[{package_name}]'`. "
55
+ "Or use `uv add 'mirascope[all]'` to support all optional features."
56
+ )
57
+
58
+
59
+ class _StubMeta(type):
60
+ """Metaclass for stub classes that fail on actual use.
61
+
62
+ This metaclass allows stub classes to be used transparently in type hints,
63
+ class definitions, and passed around as values, but fails with a helpful
64
+ error when actually used (instantiated, methods called, attributes accessed).
65
+ """
66
+
67
+ _package_name: str
68
+ _stub_name: str
69
+
70
+ def __call__(cls, *args: Any, **kwargs: Any) -> Any:
71
+ """Raise ImportError when trying to instantiate the stub class."""
72
+ raise _make_import_error(cls._package_name, cls._stub_name)
73
+
74
+ def __getattr__(cls, name: str) -> Any:
75
+ """Raise ImportError when accessing class attributes (except private/dunder)."""
76
+ # Allow private/dunder attributes to raise AttributeError normally
77
+ if name.startswith("_"):
78
+ raise AttributeError(name)
79
+ raise _make_import_error(cls._package_name, cls._stub_name)
80
+
81
+ def __instancecheck__(cls, instance: Any) -> bool:
82
+ """Raise ImportError when checking isinstance()."""
83
+ raise _make_import_error(cls._package_name, cls._stub_name)
84
+
85
+ def __subclasscheck__(cls, subclass: Any) -> bool:
86
+ """Allow the stub to be subclassed, but raise ImportError for issubclass checks.
87
+
88
+ This allows code like `class MyTrace(Trace): pass` to work
89
+ at definition time. The subclass will inherit _StubMeta, so using IT
90
+ will also fail appropriately.
91
+ """
92
+ if subclass is cls:
93
+ return True
94
+ # For issubclass() checks with other classes, fail
95
+ raise _make_import_error(cls._package_name, cls._stub_name)
96
+
97
+
98
+ def _create_stub(package_name: str, name: str) -> type:
99
+ """Create a universal stub that works as a class or callable.
100
+
101
+ Args:
102
+ package_name: The package/extra name (e.g., "ops", "api")
103
+ name: The name of the item being stubbed (e.g., "trace", "settings")
104
+
105
+ Returns:
106
+ A stub class with _StubMeta metaclass
107
+ """
108
+ return _StubMeta(
109
+ name,
110
+ (),
111
+ {
112
+ "_package_name": package_name,
113
+ "_stub_name": name,
114
+ "__module__": f"mirascope.{package_name}",
115
+ },
116
+ )
117
+
118
+
119
+ class _StubLoader(Loader):
120
+ """Loader that creates stub modules for missing submodules."""
121
+
122
+ def __init__(self, fullname: str, package_name: str) -> None:
123
+ """Initialize the stub loader.
124
+
125
+ Args:
126
+ fullname: The full module name being loaded
127
+ package_name: The package/extra name for error messages
128
+ """
129
+ self.fullname = fullname
130
+ self.package_name = package_name
131
+
132
+ def create_module(self, spec: ModuleSpec) -> ModuleType:
133
+ """Create a stub module.
134
+
135
+ Args:
136
+ spec: The module spec
137
+
138
+ Returns:
139
+ A new _StubModule instance
140
+ """
141
+ return _StubModule(self.fullname, self.package_name)
142
+
143
+ def exec_module(self, module: ModuleType) -> None:
144
+ """Execute the module (no-op for stubs).
145
+
146
+ Args:
147
+ module: The module to execute
148
+ """
149
+ pass # Stub modules don't need execution
150
+
151
+
152
+ class _StubFinder(MetaPathFinder):
153
+ """Meta path finder that intercepts imports for stubbed modules."""
154
+
155
+ def __init__(self) -> None:
156
+ """Initialize the stub finder."""
157
+ self.stubbed_modules: set[str] = set()
158
+
159
+ def register_stub(self, module_path: str) -> None:
160
+ """Register a module path as stubbed.
161
+
162
+ Args:
163
+ module_path: The full module path that's been stubbed
164
+ """
165
+ self.stubbed_modules.add(module_path)
166
+
167
+ def find_spec(
168
+ self, fullname: str, path: Any = None, target: Any = None
169
+ ) -> ModuleSpec | None:
170
+ """Find a module spec for stubbed submodules.
171
+
172
+ Args:
173
+ fullname: The full name of the module being imported
174
+ path: The path to search (unused)
175
+ target: The target module (unused)
176
+
177
+ Returns:
178
+ A ModuleSpec if this is a submodule of a stubbed module, None otherwise
179
+ """
180
+ # Check if this import is for a submodule of any stubbed module
181
+ for stub_root in self.stubbed_modules:
182
+ if fullname.startswith(f"{stub_root}."):
183
+ # Extract the package name from the stub root
184
+ # e.g., "mirascope.llm.providers.openai" -> find package_name
185
+ if fullname in sys.modules and isinstance(
186
+ sys.modules[fullname], _StubModule
187
+ ):
188
+ # Already stubbed
189
+ return None
190
+
191
+ # Get the package_name from the parent stub module
192
+ parent_module = sys.modules.get(stub_root)
193
+ if isinstance(parent_module, _StubModule):
194
+ # Use the parent's package name
195
+ package_name = parent_module._StubModule__package_name
196
+ return ModuleSpec(
197
+ fullname,
198
+ _StubLoader(fullname, package_name),
199
+ is_package=True,
200
+ )
201
+
202
+ return None
203
+
204
+
205
+ # Global finder instance
206
+ _finder = _StubFinder()
207
+
208
+
209
+ class _StubModule(ModuleType):
210
+ """A module that returns stubs for all attribute access.
211
+
212
+ This allows the entire module to be stubbed, so any imports from it will
213
+ work transparently for type checking but fail with helpful errors on actual use.
214
+
215
+ For nested module imports like `from .openai.completions.provider import X`,
216
+ this dynamically registers child stub modules in sys.modules when accessed.
217
+
218
+ Each stub module instance can also act like a stub class - it can be called,
219
+ subclassed, and used in isinstance/issubclass checks, all of which fail with
220
+ helpful error messages.
221
+ """
222
+
223
+ def __init__(self, name: str, package_name: str) -> None:
224
+ """Initialize the stub module.
225
+
226
+ Args:
227
+ name: The full module name (e.g., "mirascope.ops._internal.tracing")
228
+ package_name: The package/extra name for error messages (e.g., "ops")
229
+ """
230
+ super().__init__(name)
231
+ self.__package_name = package_name
232
+ self.__stub_name = name.split(".")[-1] # Use last part for error messages
233
+ self.__stubs: dict[str, Any] = {}
234
+ # Set __path__ to make this look like a package to Python's import system
235
+ # This allows nested imports like `from .openai.completions import X` to work
236
+ self.__path__: MutableSequence[str] = []
237
+
238
+ def __call__(self, *args: Any, **kwargs: Any) -> Any:
239
+ """Raise ImportError when trying to instantiate/call the stub.
240
+
241
+ Raises:
242
+ ImportError: With installation instructions
243
+ """
244
+ raise _make_import_error(self.__package_name, self.__stub_name)
245
+
246
+ def __getattr__(self, name: str) -> Any:
247
+ """Return a stub for any accessed attribute.
248
+
249
+ For nested imports like `from .openai.completions.provider import X`, the
250
+ _StubFinder will create intermediate stub modules automatically. This method
251
+ handles direct attribute access for both getting submodules and getting
252
+ classes/functions from the stub.
253
+
254
+ Args:
255
+ name: The attribute name being accessed
256
+
257
+ Returns:
258
+ Either a stub module (if already in sys.modules) or a stub class
259
+
260
+ Raises:
261
+ AttributeError: For private/dunder attributes
262
+ """
263
+ if name.startswith("_"):
264
+ raise AttributeError(name)
265
+
266
+ # Check if we've already created a stub for this name
267
+ if name in self.__stubs:
268
+ return self.__stubs[name]
269
+
270
+ # Check if there's a submodule already created by the finder
271
+ full_name = f"{self.__name__}.{name}"
272
+ if full_name in sys.modules:
273
+ submodule = sys.modules[full_name]
274
+ self.__stubs[name] = submodule
275
+ return submodule
276
+
277
+ # Otherwise return a stub class for direct attribute access
278
+ stub_class = _create_stub(self.__package_name, name)
279
+ self.__stubs[name] = stub_class
280
+ return stub_class
281
+
282
+ def __instancecheck__(self, instance: Any) -> bool:
283
+ """Raise ImportError when checking isinstance().
284
+
285
+ Raises:
286
+ ImportError: With installation instructions
287
+ """
288
+ raise _make_import_error(self.__package_name, self.__stub_name)
289
+
290
+ def __subclasscheck__(self, subclass: Any) -> bool:
291
+ """Allow subclassing but raise ImportError for issubclass checks.
292
+
293
+ Args:
294
+ subclass: The class being checked
295
+
296
+ Returns:
297
+ True if checking against self
298
+
299
+ Raises:
300
+ ImportError: For issubclass checks with other classes
301
+ """
302
+ if subclass is self:
303
+ return True
304
+ raise _make_import_error(self.__package_name, self.__stub_name)
305
+
306
+ def __dir__(self) -> list[str]:
307
+ """Return empty list to avoid advertising stub names.
308
+
309
+ Returns:
310
+ Empty list
311
+ """
312
+ return []
313
+
314
+
315
+ def stub_module_if_missing(
316
+ module_path: str,
317
+ package_name: str,
318
+ ) -> bool:
319
+ """Check if all packages for an extra are installed; if not, install a stub module.
320
+
321
+ This must be called BEFORE importing from the module.
322
+
323
+ Args:
324
+ module_path: Full module path to stub (e.g., 'mirascope.ops._internal.tracing')
325
+ package_name: The extra name (e.g., 'ops'). Must exist in EXTRA_IMPORTS.
326
+
327
+ Returns:
328
+ True if all packages for the extra are available, False if stubbed.
329
+
330
+ Raises:
331
+ KeyError: If package_name is not found in EXTRA_IMPORTS mapping.
332
+ """
333
+ if package_name not in EXTRA_IMPORTS:
334
+ raise KeyError(
335
+ f"Unknown extra '{package_name}'. "
336
+ f"Available extras: {', '.join(EXTRA_IMPORTS.keys())}"
337
+ )
338
+
339
+ imports_to_check = EXTRA_IMPORTS[package_name]
340
+
341
+ # Check if ALL imports for this extra are available
342
+ all_available = True
343
+ for import_name in imports_to_check:
344
+ try:
345
+ __import__(import_name)
346
+ except ImportError:
347
+ all_available = False
348
+ break
349
+
350
+ if all_available:
351
+ return True
352
+
353
+ # At least one import is missing, so stub the module
354
+ sys.modules[module_path] = _StubModule(module_path, package_name)
355
+
356
+ # Register with the finder to handle nested imports
357
+ _finder.register_stub(module_path)
358
+
359
+ # Ensure the finder is in sys.meta_path (only add once)
360
+ if _finder not in sys.meta_path:
361
+ sys.meta_path.insert(0, _finder)
362
+
363
+ return False
mirascope/api/__init__.py CHANGED
@@ -1,5 +1,13 @@
1
1
  """The Mirascope Cloud API client."""
2
2
 
3
+ from .._stubs import stub_module_if_missing
4
+
5
+ # Stub modules for missing optional dependencies BEFORE importing
6
+ # This must happen before any imports from these modules
7
+ stub_module_if_missing("mirascope.api", "api")
8
+
9
+ # Now imports work regardless of which packages are installed
10
+ # ruff: noqa: E402
3
11
  from .client import AsyncMirascope, Mirascope
4
12
  from .settings import get_settings, settings
5
13