anthropic 1.1.1 → 1.9.0

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 (331) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +170 -0
  3. data/README.md +32 -16
  4. data/lib/anthropic/client.rb +5 -2
  5. data/lib/anthropic/errors.rb +22 -0
  6. data/lib/anthropic/helpers/bedrock/client.rb +34 -4
  7. data/lib/anthropic/helpers/input_schema/array_of.rb +41 -0
  8. data/lib/anthropic/helpers/input_schema/base_model.rb +86 -0
  9. data/lib/anthropic/helpers/input_schema/boolean.rb +29 -0
  10. data/lib/anthropic/helpers/input_schema/enum_of.rb +63 -0
  11. data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +199 -0
  12. data/lib/anthropic/helpers/input_schema/parsed_json.rb +39 -0
  13. data/lib/anthropic/helpers/input_schema/property_mapping.rb +47 -0
  14. data/lib/anthropic/helpers/input_schema/union_of.rb +56 -0
  15. data/lib/anthropic/helpers/input_schema.rb +16 -0
  16. data/lib/anthropic/helpers/streaming/events.rb +141 -0
  17. data/lib/anthropic/helpers/streaming/message_stream.rb +278 -0
  18. data/lib/anthropic/helpers/streaming.rb +37 -0
  19. data/lib/anthropic/helpers/vertex/client.rb +4 -1
  20. data/lib/anthropic/input_schema.rb +10 -0
  21. data/lib/anthropic/internal/stream.rb +6 -3
  22. data/lib/anthropic/internal/transport/base_client.rb +30 -5
  23. data/lib/anthropic/internal/transport/pooled_net_requester.rb +1 -9
  24. data/lib/anthropic/internal/type/array_of.rb +7 -1
  25. data/lib/anthropic/internal/type/base_model.rb +81 -32
  26. data/lib/anthropic/internal/type/base_stream.rb +3 -1
  27. data/lib/anthropic/internal/type/boolean.rb +7 -1
  28. data/lib/anthropic/internal/type/converter.rb +69 -34
  29. data/lib/anthropic/internal/type/enum.rb +16 -5
  30. data/lib/anthropic/internal/type/file_input.rb +6 -1
  31. data/lib/anthropic/internal/type/hash_of.rb +7 -1
  32. data/lib/anthropic/internal/type/union.rb +26 -16
  33. data/lib/anthropic/internal/type/unknown.rb +7 -1
  34. data/lib/anthropic/internal/util.rb +10 -11
  35. data/lib/anthropic/models/anthropic_beta.rb +3 -0
  36. data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +1 -65
  37. data/lib/anthropic/models/beta/beta_bash_code_execution_output_block.rb +25 -0
  38. data/lib/anthropic/models/beta/beta_bash_code_execution_output_block_param.rb +25 -0
  39. data/lib/anthropic/models/beta/beta_bash_code_execution_result_block.rb +44 -0
  40. data/lib/anthropic/models/beta/beta_bash_code_execution_result_block_param.rb +44 -0
  41. data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rb +43 -0
  42. data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rb +53 -0
  43. data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rb +39 -0
  44. data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rb +39 -0
  45. data/lib/anthropic/models/beta/beta_citation_char_location.rb +7 -1
  46. data/lib/anthropic/models/beta/beta_citation_config.rb +19 -0
  47. data/lib/anthropic/models/beta/beta_citation_content_block_location.rb +7 -1
  48. data/lib/anthropic/models/beta/beta_citation_page_location.rb +7 -1
  49. data/lib/anthropic/models/beta/beta_citation_search_result_location.rb +55 -0
  50. data/lib/anthropic/models/beta/beta_citation_search_result_location_param.rb +55 -0
  51. data/lib/anthropic/models/beta/beta_citations_delta.rb +5 -3
  52. data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +40 -0
  53. data/lib/anthropic/models/beta/beta_content_block.rb +12 -5
  54. data/lib/anthropic/models/beta/beta_content_block_param.rb +28 -17
  55. data/lib/anthropic/models/beta/beta_document_block.rb +56 -0
  56. data/lib/anthropic/models/beta/beta_message.rb +6 -2
  57. data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
  58. data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +14 -7
  59. data/lib/anthropic/models/beta/beta_request_document_block.rb +75 -0
  60. data/lib/anthropic/models/beta/beta_search_result_block_param.rb +55 -0
  61. data/lib/anthropic/models/beta/beta_server_tool_usage.rb +9 -1
  62. data/lib/anthropic/models/beta/beta_server_tool_use_block.rb +3 -0
  63. data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +3 -0
  64. data/lib/anthropic/models/beta/beta_text_block.rb +2 -2
  65. data/lib/anthropic/models/beta/beta_text_block_param.rb +2 -2
  66. data/lib/anthropic/models/beta/beta_text_citation.rb +3 -1
  67. data/lib/anthropic/models/beta/beta_text_citation_param.rb +3 -1
  68. data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rb +25 -0
  69. data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rb +26 -0
  70. data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rb +49 -0
  71. data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rb +50 -0
  72. data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rb +47 -0
  73. data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rb +57 -0
  74. data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rb +45 -0
  75. data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rb +46 -0
  76. data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rb +61 -0
  77. data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rb +62 -0
  78. data/lib/anthropic/models/beta/beta_tool.rb +7 -1
  79. data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +8 -4
  80. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +49 -0
  81. data/lib/anthropic/models/beta/beta_tool_union.rb +12 -6
  82. data/lib/anthropic/models/beta/beta_web_fetch_block.rb +42 -0
  83. data/lib/anthropic/models/beta/beta_web_fetch_block_param.rb +42 -0
  84. data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +82 -0
  85. data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block.rb +43 -0
  86. data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rb +53 -0
  87. data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rb +25 -0
  88. data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rb +25 -0
  89. data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rb +25 -0
  90. data/lib/anthropic/models/beta/message_count_tokens_params.rb +23 -36
  91. data/lib/anthropic/models/beta/message_create_params.rb +10 -27
  92. data/lib/anthropic/models/beta/messages/batch_create_params.rb +13 -37
  93. data/lib/anthropic/models/beta/messages/beta_message_batch.rb +1 -4
  94. data/lib/anthropic/models/beta_error_response.rb +7 -1
  95. data/lib/anthropic/models/cache_control_ephemeral.rb +39 -1
  96. data/lib/anthropic/models/cache_creation.rb +24 -0
  97. data/lib/anthropic/models/citation_char_location.rb +7 -1
  98. data/lib/anthropic/models/citation_content_block_location.rb +7 -1
  99. data/lib/anthropic/models/citation_page_location.rb +7 -1
  100. data/lib/anthropic/models/citation_search_result_location_param.rb +51 -0
  101. data/lib/anthropic/models/citations_delta.rb +5 -3
  102. data/lib/anthropic/models/citations_search_result_location.rb +51 -0
  103. data/lib/anthropic/models/content_block.rb +5 -5
  104. data/lib/anthropic/models/content_block_param.rb +14 -11
  105. data/lib/anthropic/models/document_block_param.rb +2 -2
  106. data/lib/anthropic/models/error_response.rb +7 -1
  107. data/lib/anthropic/models/message.rb +6 -2
  108. data/lib/anthropic/models/message_count_tokens_params.rb +10 -27
  109. data/lib/anthropic/models/message_count_tokens_tool.rb +5 -1
  110. data/lib/anthropic/models/message_create_params.rb +10 -27
  111. data/lib/anthropic/models/message_param.rb +3 -3
  112. data/lib/anthropic/models/messages/batch_create_params.rb +11 -31
  113. data/lib/anthropic/models/model.rb +16 -21
  114. data/lib/anthropic/models/raw_content_block_start_event.rb +7 -7
  115. data/lib/anthropic/models/search_result_block_param.rb +51 -0
  116. data/lib/anthropic/models/text_block.rb +2 -2
  117. data/lib/anthropic/models/text_block_param.rb +2 -2
  118. data/lib/anthropic/models/text_citation.rb +3 -1
  119. data/lib/anthropic/models/text_citation_param.rb +3 -1
  120. data/lib/anthropic/models/tool.rb +7 -1
  121. data/lib/anthropic/models/tool_result_block_param.rb +8 -4
  122. data/lib/anthropic/models/tool_text_editor_20250429.rb +36 -0
  123. data/lib/anthropic/models/tool_text_editor_20250728.rb +45 -0
  124. data/lib/anthropic/models/tool_union.rb +5 -1
  125. data/lib/anthropic/models/tool_use_block.rb +14 -0
  126. data/lib/anthropic/models/usage.rb +9 -1
  127. data/lib/anthropic/models.rb +16 -4
  128. data/lib/anthropic/resources/beta/messages.rb +73 -6
  129. data/lib/anthropic/resources/messages.rb +152 -7
  130. data/lib/anthropic/streaming.rb +5 -0
  131. data/lib/anthropic/version.rb +1 -1
  132. data/lib/anthropic.rb +54 -0
  133. data/rbi/anthropic/errors.rbi +18 -2
  134. data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
  135. data/rbi/anthropic/helpers/input_schema/array_of.rbi +16 -0
  136. data/rbi/anthropic/helpers/input_schema/base_model.rbi +21 -0
  137. data/rbi/anthropic/helpers/input_schema/boolean.rbi +11 -0
  138. data/rbi/anthropic/helpers/input_schema/enum_of.rbi +30 -0
  139. data/rbi/anthropic/helpers/input_schema/json_schema_converter.rbi +89 -0
  140. data/rbi/anthropic/helpers/input_schema/union_of.rbi +23 -0
  141. data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
  142. data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
  143. data/rbi/anthropic/helpers/structured_output.rbi +16 -0
  144. data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
  145. data/rbi/anthropic/input_schema.rbi +12 -0
  146. data/rbi/anthropic/internal/transport/base_client.rbi +1 -1
  147. data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
  148. data/rbi/anthropic/internal/type/boolean.rbi +2 -0
  149. data/rbi/anthropic/internal/type/converter.rbi +69 -15
  150. data/rbi/anthropic/internal/type/union.rbi +14 -2
  151. data/rbi/anthropic/internal/type/unknown.rbi +2 -0
  152. data/rbi/anthropic/internal/util.rbi +2 -0
  153. data/rbi/anthropic/models/anthropic_beta.rbi +2 -0
  154. data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
  155. data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block.rbi +33 -0
  156. data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbi +34 -0
  157. data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block.rbi +72 -0
  158. data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbi +77 -0
  159. data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbi +86 -0
  160. data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbi +110 -0
  161. data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbi +101 -0
  162. data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbi +101 -0
  163. data/rbi/anthropic/models/beta/beta_citation_char_location.rbi +6 -0
  164. data/rbi/anthropic/models/beta/beta_citation_config.rbi +30 -0
  165. data/rbi/anthropic/models/beta/beta_citation_content_block_location.rbi +6 -0
  166. data/rbi/anthropic/models/beta/beta_citation_page_location.rbi +6 -0
  167. data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
  168. data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
  169. data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
  170. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +72 -0
  171. data/rbi/anthropic/models/beta/beta_content_block.rbi +6 -3
  172. data/rbi/anthropic/models/beta/beta_content_block_param.rbi +11 -7
  173. data/rbi/anthropic/models/beta/beta_document_block.rbi +95 -0
  174. data/rbi/anthropic/models/beta/beta_message.rbi +14 -3
  175. data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +12 -6
  176. data/rbi/anthropic/models/beta/beta_request_document_block.rbi +142 -0
  177. data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
  178. data/rbi/anthropic/models/beta/beta_server_tool_usage.rbi +17 -2
  179. data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +15 -0
  180. data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +15 -0
  181. data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
  182. data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
  183. data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
  184. data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
  185. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbi +41 -0
  186. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbi +41 -0
  187. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbi +73 -0
  188. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbi +73 -0
  189. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbi +90 -0
  190. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbi +118 -0
  191. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbi +110 -0
  192. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbi +110 -0
  193. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbi +118 -0
  194. data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbi +118 -0
  195. data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
  196. data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +3 -1
  197. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +82 -0
  198. data/rbi/anthropic/models/beta/beta_tool_union.rbi +7 -4
  199. data/rbi/anthropic/models/beta/beta_web_fetch_block.rbi +67 -0
  200. data/rbi/anthropic/models/beta/beta_web_fetch_block_param.rbi +71 -0
  201. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +125 -0
  202. data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block.rbi +81 -0
  203. data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbi +109 -0
  204. data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbi +51 -0
  205. data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbi +50 -0
  206. data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbi +70 -0
  207. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +51 -70
  208. data/rbi/anthropic/models/beta/message_create_params.rbi +44 -66
  209. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +44 -66
  210. data/rbi/anthropic/models/beta_error_response.rbi +10 -2
  211. data/rbi/anthropic/models/cache_control_ephemeral.rbi +68 -3
  212. data/rbi/anthropic/models/cache_creation.rbi +45 -0
  213. data/rbi/anthropic/models/citation_char_location.rbi +6 -0
  214. data/rbi/anthropic/models/citation_content_block_location.rbi +6 -0
  215. data/rbi/anthropic/models/citation_page_location.rbi +6 -0
  216. data/rbi/anthropic/models/citation_search_result_location_param.rbi +74 -0
  217. data/rbi/anthropic/models/citations_delta.rbi +4 -2
  218. data/rbi/anthropic/models/citations_search_result_location.rbi +74 -0
  219. data/rbi/anthropic/models/content_block.rbi +3 -3
  220. data/rbi/anthropic/models/content_block_param.rbi +6 -5
  221. data/rbi/anthropic/models/document_block_param.rbi +7 -3
  222. data/rbi/anthropic/models/error_response.rbi +10 -2
  223. data/rbi/anthropic/models/message.rbi +11 -3
  224. data/rbi/anthropic/models/message_count_tokens_params.rbi +24 -50
  225. data/rbi/anthropic/models/message_count_tokens_tool.rbi +2 -0
  226. data/rbi/anthropic/models/message_create_params.rbi +24 -50
  227. data/rbi/anthropic/models/messages/batch_create_params.rbi +24 -50
  228. data/rbi/anthropic/models/model.rbi +4 -8
  229. data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
  230. data/rbi/anthropic/models/search_result_block_param.rbi +77 -0
  231. data/rbi/anthropic/models/text_block.rbi +2 -1
  232. data/rbi/anthropic/models/text_block_param.rbi +6 -3
  233. data/rbi/anthropic/models/text_citation.rbi +2 -1
  234. data/rbi/anthropic/models/text_citation_param.rbi +2 -1
  235. data/rbi/anthropic/models/tool.rbi +16 -5
  236. data/rbi/anthropic/models/tool_result_block_param.rbi +6 -1
  237. data/rbi/anthropic/models/tool_text_editor_20250429.rbi +62 -0
  238. data/rbi/anthropic/models/tool_text_editor_20250728.rbi +72 -0
  239. data/rbi/anthropic/models/tool_union.rbi +2 -0
  240. data/rbi/anthropic/models/usage.rbi +13 -0
  241. data/rbi/anthropic/models.rbi +14 -0
  242. data/rbi/anthropic/resources/beta/messages.rbi +45 -87
  243. data/rbi/anthropic/resources/messages.rbi +315 -69
  244. data/rbi/anthropic/streaming.rbi +5 -0
  245. data/sig/anthropic/errors.rbs +9 -0
  246. data/sig/anthropic/helpers/streaming/events.rbs +117 -0
  247. data/sig/anthropic/helpers/streaming/message_stream.rbs +57 -0
  248. data/sig/anthropic/internal/transport/base_client.rbs +1 -1
  249. data/sig/anthropic/internal/type/base_stream.rbs +4 -0
  250. data/sig/anthropic/internal/type/converter.rbs +24 -1
  251. data/sig/anthropic/internal/type/union.rbs +2 -2
  252. data/sig/anthropic/models/anthropic_beta.rbs +2 -0
  253. data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
  254. data/sig/anthropic/models/beta/beta_bash_code_execution_output_block.rbs +23 -0
  255. data/sig/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbs +23 -0
  256. data/sig/anthropic/models/beta/beta_bash_code_execution_result_block.rbs +44 -0
  257. data/sig/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbs +44 -0
  258. data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbs +44 -0
  259. data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbs +49 -0
  260. data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbs +48 -0
  261. data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbs +48 -0
  262. data/sig/anthropic/models/beta/beta_citation_char_location.rbs +5 -0
  263. data/sig/anthropic/models/beta/beta_citation_config.rbs +17 -0
  264. data/sig/anthropic/models/beta/beta_citation_content_block_location.rbs +5 -0
  265. data/sig/anthropic/models/beta/beta_citation_page_location.rbs +5 -0
  266. data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
  267. data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
  268. data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
  269. data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +34 -0
  270. data/sig/anthropic/models/beta/beta_content_block.rbs +5 -2
  271. data/sig/anthropic/models/beta/beta_content_block_param.rbs +12 -8
  272. data/sig/anthropic/models/beta/beta_document_block.rbs +49 -0
  273. data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +5 -2
  274. data/sig/anthropic/models/beta/beta_request_document_block.rbs +62 -0
  275. data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
  276. data/sig/anthropic/models/beta/beta_server_tool_usage.rbs +12 -3
  277. data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +9 -1
  278. data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +9 -1
  279. data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
  280. data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
  281. data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbs +29 -0
  282. data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbs +29 -0
  283. data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbs +49 -0
  284. data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbs +49 -0
  285. data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbs +46 -0
  286. data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbs +51 -0
  287. data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbs +53 -0
  288. data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbs +53 -0
  289. data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbs +61 -0
  290. data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbs +61 -0
  291. data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
  292. data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +2 -0
  293. data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +39 -0
  294. data/sig/anthropic/models/beta/beta_tool_union.rbs +7 -4
  295. data/sig/anthropic/models/beta/beta_web_fetch_block.rbs +39 -0
  296. data/sig/anthropic/models/beta/beta_web_fetch_block_param.rbs +39 -0
  297. data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +59 -0
  298. data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block.rbs +44 -0
  299. data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbs +49 -0
  300. data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbs +29 -0
  301. data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbs +29 -0
  302. data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbs +32 -0
  303. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +7 -4
  304. data/sig/anthropic/models/beta_error_response.rbs +13 -2
  305. data/sig/anthropic/models/cache_control_ephemeral.rbs +27 -3
  306. data/sig/anthropic/models/cache_creation.rbs +25 -0
  307. data/sig/anthropic/models/citation_char_location.rbs +5 -0
  308. data/sig/anthropic/models/citation_content_block_location.rbs +5 -0
  309. data/sig/anthropic/models/citation_page_location.rbs +5 -0
  310. data/sig/anthropic/models/citation_search_result_location_param.rbs +50 -0
  311. data/sig/anthropic/models/citations_delta.rbs +1 -0
  312. data/sig/anthropic/models/citations_search_result_location.rbs +50 -0
  313. data/sig/anthropic/models/content_block.rbs +2 -2
  314. data/sig/anthropic/models/content_block_param.rbs +6 -5
  315. data/sig/anthropic/models/document_block_param.rbs +4 -8
  316. data/sig/anthropic/models/error_response.rbs +13 -2
  317. data/sig/anthropic/models/message_count_tokens_tool.rbs +2 -0
  318. data/sig/anthropic/models/model.rbs +4 -10
  319. data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
  320. data/sig/anthropic/models/search_result_block_param.rbs +49 -0
  321. data/sig/anthropic/models/text_citation.rbs +1 -0
  322. data/sig/anthropic/models/text_citation_param.rbs +1 -0
  323. data/sig/anthropic/models/tool.rbs +14 -3
  324. data/sig/anthropic/models/tool_result_block_param.rbs +5 -1
  325. data/sig/anthropic/models/tool_text_editor_20250429.rbs +30 -0
  326. data/sig/anthropic/models/tool_text_editor_20250728.rbs +35 -0
  327. data/sig/anthropic/models/tool_union.rbs +2 -0
  328. data/sig/anthropic/models/usage.rbs +5 -0
  329. data/sig/anthropic/models.rbs +12 -0
  330. data/sig/anthropic/streaming.rbs +3 -0
  331. metadata +152 -3
@@ -43,6 +43,8 @@ module Anthropic
43
43
  Anthropic::Tool::OrHash,
44
44
  Anthropic::ToolBash20250124::OrHash,
45
45
  Anthropic::ToolTextEditor20250124::OrHash,
46
+ Anthropic::ToolTextEditor20250429::OrHash,
47
+ Anthropic::ToolTextEditor20250728::OrHash,
46
48
  Anthropic::WebSearchTool20250305::OrHash
47
49
  )
48
50
  ],
@@ -53,6 +55,298 @@ module Anthropic
53
55
  ).returns(Anthropic::Message)
54
56
  end
55
57
  def create(
58
+ # The maximum number of tokens to generate before stopping.
59
+ #
60
+ # Note that our models may stop _before_ reaching this maximum. This parameter
61
+ # only specifies the absolute maximum number of tokens to generate.
62
+ #
63
+ # Different models have different maximum values for this parameter. See
64
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for details.
65
+ max_tokens:,
66
+ # Input messages.
67
+ #
68
+ # Our models are trained to operate on alternating `user` and `assistant`
69
+ # conversational turns. When creating a new `Message`, you specify the prior
70
+ # conversational turns with the `messages` parameter, and the model then generates
71
+ # the next `Message` in the conversation. Consecutive `user` or `assistant` turns
72
+ # in your request will be combined into a single turn.
73
+ #
74
+ # Each input message must be an object with a `role` and `content`. You can
75
+ # specify a single `user`-role message, or you can include multiple `user` and
76
+ # `assistant` messages.
77
+ #
78
+ # If the final message uses the `assistant` role, the response content will
79
+ # continue immediately from the content in that message. This can be used to
80
+ # constrain part of the model's response.
81
+ #
82
+ # Example with a single `user` message:
83
+ #
84
+ # ```json
85
+ # [{ "role": "user", "content": "Hello, Claude" }]
86
+ # ```
87
+ #
88
+ # Example with multiple conversational turns:
89
+ #
90
+ # ```json
91
+ # [
92
+ # { "role": "user", "content": "Hello there." },
93
+ # { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
94
+ # { "role": "user", "content": "Can you explain LLMs in plain English?" }
95
+ # ]
96
+ # ```
97
+ #
98
+ # Example with a partially-filled response from Claude:
99
+ #
100
+ # ```json
101
+ # [
102
+ # {
103
+ # "role": "user",
104
+ # "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
105
+ # },
106
+ # { "role": "assistant", "content": "The best answer is (" }
107
+ # ]
108
+ # ```
109
+ #
110
+ # Each input message `content` may be either a single `string` or an array of
111
+ # content blocks, where each block has a specific `type`. Using a `string` for
112
+ # `content` is shorthand for an array of one content block of type `"text"`. The
113
+ # following input messages are equivalent:
114
+ #
115
+ # ```json
116
+ # { "role": "user", "content": "Hello, Claude" }
117
+ # ```
118
+ #
119
+ # ```json
120
+ # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
121
+ # ```
122
+ #
123
+ # See [input examples](https://docs.anthropic.com/en/api/messages-examples).
124
+ #
125
+ # Note that if you want to include a
126
+ # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
127
+ # the top-level `system` parameter — there is no `"system"` role for input
128
+ # messages in the Messages API.
129
+ #
130
+ # There is a limit of 100,000 messages in a single request.
131
+ messages:,
132
+ # The model that will complete your prompt.\n\nSee
133
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
134
+ # details and options.
135
+ model:,
136
+ # An object describing metadata about the request.
137
+ metadata: nil,
138
+ # Determines whether to use priority capacity (if available) or standard capacity
139
+ # for this request.
140
+ #
141
+ # Anthropic offers different levels of service for your API requests. See
142
+ # [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
143
+ service_tier: nil,
144
+ # Custom text sequences that will cause the model to stop generating.
145
+ #
146
+ # Our models will normally stop when they have naturally completed their turn,
147
+ # which will result in a response `stop_reason` of `"end_turn"`.
148
+ #
149
+ # If you want the model to stop generating when it encounters custom strings of
150
+ # text, you can use the `stop_sequences` parameter. If the model encounters one of
151
+ # the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
152
+ # and the response `stop_sequence` value will contain the matched stop sequence.
153
+ stop_sequences: nil,
154
+ # System prompt.
155
+ #
156
+ # A system prompt is a way of providing context and instructions to Claude, such
157
+ # as specifying a particular goal or role. See our
158
+ # [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
159
+ system_: nil,
160
+ # Amount of randomness injected into the response.
161
+ #
162
+ # Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
163
+ # for analytical / multiple choice, and closer to `1.0` for creative and
164
+ # generative tasks.
165
+ #
166
+ # Note that even with `temperature` of `0.0`, the results will not be fully
167
+ # deterministic.
168
+ temperature: nil,
169
+ # Configuration for enabling Claude's extended thinking.
170
+ #
171
+ # When enabled, responses include `thinking` content blocks showing Claude's
172
+ # thinking process before the final answer. Requires a minimum budget of 1,024
173
+ # tokens and counts towards your `max_tokens` limit.
174
+ #
175
+ # See
176
+ # [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
177
+ # for details.
178
+ thinking: nil,
179
+ # How the model should use the provided tools. The model can use a specific tool,
180
+ # any available tool, decide by itself, or not use tools at all.
181
+ tool_choice: nil,
182
+ # Definitions of tools that the model may use.
183
+ #
184
+ # If you include `tools` in your API request, the model may return `tool_use`
185
+ # content blocks that represent the model's use of those tools. You can then run
186
+ # those tools using the tool input generated by the model and then optionally
187
+ # return results back to the model using `tool_result` content blocks.
188
+ #
189
+ # There are two types of tools: **client tools** and **server tools**. The
190
+ # behavior described below applies to client tools. For
191
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
192
+ # see their individual documentation as each has its own behavior (e.g., the
193
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
194
+ #
195
+ # Each tool definition includes:
196
+ #
197
+ # - `name`: Name of the tool.
198
+ # - `description`: Optional, but strongly-recommended description of the tool.
199
+ # - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
200
+ # tool `input` shape that the model will produce in `tool_use` output content
201
+ # blocks.
202
+ #
203
+ # For example, if you defined `tools` as:
204
+ #
205
+ # ```json
206
+ # [
207
+ # {
208
+ # "name": "get_stock_price",
209
+ # "description": "Get the current stock price for a given ticker symbol.",
210
+ # "input_schema": {
211
+ # "type": "object",
212
+ # "properties": {
213
+ # "ticker": {
214
+ # "type": "string",
215
+ # "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
216
+ # }
217
+ # },
218
+ # "required": ["ticker"]
219
+ # }
220
+ # }
221
+ # ]
222
+ # ```
223
+ #
224
+ # And then asked the model "What's the S&P 500 at today?", the model might produce
225
+ # `tool_use` content blocks in the response like this:
226
+ #
227
+ # ```json
228
+ # [
229
+ # {
230
+ # "type": "tool_use",
231
+ # "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
232
+ # "name": "get_stock_price",
233
+ # "input": { "ticker": "^GSPC" }
234
+ # }
235
+ # ]
236
+ # ```
237
+ #
238
+ # You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
239
+ # input, and return the following back to the model in a subsequent `user`
240
+ # message:
241
+ #
242
+ # ```json
243
+ # [
244
+ # {
245
+ # "type": "tool_result",
246
+ # "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
247
+ # "content": "259.75 USD"
248
+ # }
249
+ # ]
250
+ # ```
251
+ #
252
+ # Tools can be used for workflows that include running client-side tools and
253
+ # functions, or more generally whenever you want the model to produce a particular
254
+ # JSON structure of output.
255
+ #
256
+ # See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
257
+ tools: nil,
258
+ # Only sample from the top K options for each subsequent token.
259
+ #
260
+ # Used to remove "long tail" low probability responses.
261
+ # [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
262
+ #
263
+ # Recommended for advanced use cases only. You usually only need to use
264
+ # `temperature`.
265
+ top_k: nil,
266
+ # Use nucleus sampling.
267
+ #
268
+ # In nucleus sampling, we compute the cumulative distribution over all the options
269
+ # for each subsequent token in decreasing probability order and cut it off once it
270
+ # reaches a particular probability specified by `top_p`. You should either alter
271
+ # `temperature` or `top_p`, but not both.
272
+ #
273
+ # Recommended for advanced use cases only. You usually only need to use
274
+ # `temperature`.
275
+ top_p: nil,
276
+ # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
277
+ # for streaming and non-streaming use cases, respectively.
278
+ stream: false,
279
+ request_options: {}
280
+ )
281
+ end
282
+
283
+ # See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
284
+ #
285
+ # Send a structured list of input messages with text and/or image content, and the
286
+ # model will generate the next message in the conversation.
287
+ #
288
+ # The Messages API can be used for either single queries or stateless multi-turn
289
+ # conversations.
290
+ #
291
+ # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
292
+ sig do
293
+ params(
294
+ max_tokens: Integer,
295
+ messages:
296
+ T::Array[
297
+ T.any(
298
+ Anthropic::Models::MessageParam,
299
+ Anthropic::Internal::AnyHash
300
+ )
301
+ ],
302
+ model: T.any(Anthropic::Models::Model::OrSymbol, String),
303
+ metadata:
304
+ T.any(Anthropic::Models::Metadata, Anthropic::Internal::AnyHash),
305
+ stop_sequences: T::Array[String],
306
+ system_:
307
+ T.any(
308
+ String,
309
+ T::Array[
310
+ T.any(
311
+ Anthropic::Models::TextBlockParam,
312
+ Anthropic::Internal::AnyHash
313
+ )
314
+ ]
315
+ ),
316
+ temperature: Float,
317
+ thinking:
318
+ T.any(
319
+ Anthropic::Models::ThinkingConfigEnabled,
320
+ Anthropic::Internal::AnyHash,
321
+ Anthropic::Models::ThinkingConfigDisabled
322
+ ),
323
+ tool_choice:
324
+ T.any(
325
+ Anthropic::Models::ToolChoiceAuto,
326
+ Anthropic::Internal::AnyHash,
327
+ Anthropic::Models::ToolChoiceAny,
328
+ Anthropic::Models::ToolChoiceTool,
329
+ Anthropic::Models::ToolChoiceNone
330
+ ),
331
+ tools:
332
+ T::Array[
333
+ T.any(
334
+ Anthropic::Models::Tool,
335
+ Anthropic::Internal::AnyHash,
336
+ Anthropic::Models::ToolBash20250124,
337
+ Anthropic::Models::ToolTextEditor20250124
338
+ )
339
+ ],
340
+ top_k: Integer,
341
+ top_p: Float,
342
+ stream: T.noreturn,
343
+ request_options:
344
+ T.nilable(
345
+ T.any(Anthropic::RequestOptions, Anthropic::Internal::AnyHash)
346
+ )
347
+ ).returns(Anthropic::Helpers::Streaming::MessageStream)
348
+ end
349
+ def stream(
56
350
  # The maximum number of tokens to generate before stopping.
57
351
  #
58
352
  # Note that our models may stop _before_ reaching this maximum. This parameter
@@ -147,8 +441,6 @@ module Anthropic
147
441
  # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
148
442
  # the top-level `system` parameter — there is no `"system"` role for input
149
443
  # messages in the Messages API.
150
- #
151
- # There is a limit of 100000 messages in a single request.
152
444
  messages:,
153
445
  # The model that will complete your prompt.\n\nSee
154
446
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -156,12 +448,6 @@ module Anthropic
156
448
  model:,
157
449
  # An object describing metadata about the request.
158
450
  metadata: nil,
159
- # Determines whether to use priority capacity (if available) or standard capacity
160
- # for this request.
161
- #
162
- # Anthropic offers different levels of service for your API requests. See
163
- # [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
164
- service_tier: nil,
165
451
  # Custom text sequences that will cause the model to stop generating.
166
452
  #
167
453
  # Our models will normally stop when they have naturally completed their turn,
@@ -290,20 +576,10 @@ module Anthropic
290
576
  top_p: nil,
291
577
  # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
292
578
  # for streaming and non-streaming use cases, respectively.
293
- stream: false,
579
+ stream: true,
294
580
  request_options: {}
295
581
  )
296
582
  end
297
-
298
- # See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
299
- #
300
- # Send a structured list of input messages with text and/or image content, and the
301
- # model will generate the next message in the conversation.
302
- #
303
- # The Messages API can be used for either single queries or stateless multi-turn
304
- # conversations.
305
- #
306
- # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
307
583
  sig do
308
584
  params(
309
585
  max_tokens: Integer,
@@ -332,6 +608,8 @@ module Anthropic
332
608
  Anthropic::Tool::OrHash,
333
609
  Anthropic::ToolBash20250124::OrHash,
334
610
  Anthropic::ToolTextEditor20250124::OrHash,
611
+ Anthropic::ToolTextEditor20250429::OrHash,
612
+ Anthropic::ToolTextEditor20250728::OrHash,
335
613
  Anthropic::WebSearchTool20250305::OrHash
336
614
  )
337
615
  ],
@@ -411,37 +689,14 @@ module Anthropic
411
689
  # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
412
690
  # ```
413
691
  #
414
- # Starting with Claude 3 models, you can also send image content blocks:
415
- #
416
- # ```json
417
- # {
418
- # "role": "user",
419
- # "content": [
420
- # {
421
- # "type": "image",
422
- # "source": {
423
- # "type": "base64",
424
- # "media_type": "image/jpeg",
425
- # "data": "/9j/4AAQSkZJRg..."
426
- # }
427
- # },
428
- # { "type": "text", "text": "What is in this image?" }
429
- # ]
430
- # }
431
- # ```
432
- #
433
- # We currently support the `base64` source type for images, and the `image/jpeg`,
434
- # `image/png`, `image/gif`, and `image/webp` media types.
435
- #
436
- # See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
437
- # more input examples.
692
+ # See [input examples](https://docs.anthropic.com/en/api/messages-examples).
438
693
  #
439
694
  # Note that if you want to include a
440
695
  # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
441
696
  # the top-level `system` parameter — there is no `"system"` role for input
442
697
  # messages in the Messages API.
443
698
  #
444
- # There is a limit of 100000 messages in a single request.
699
+ # There is a limit of 100,000 messages in a single request.
445
700
  messages:,
446
701
  # The model that will complete your prompt.\n\nSee
447
702
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -500,6 +755,12 @@ module Anthropic
500
755
  # those tools using the tool input generated by the model and then optionally
501
756
  # return results back to the model using `tool_result` content blocks.
502
757
  #
758
+ # There are two types of tools: **client tools** and **server tools**. The
759
+ # behavior described below applies to client tools. For
760
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
761
+ # see their individual documentation as each has its own behavior (e.g., the
762
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
763
+ #
503
764
  # Each tool definition includes:
504
765
  #
505
766
  # - `name`: Name of the tool.
@@ -618,6 +879,8 @@ module Anthropic
618
879
  Anthropic::Tool::OrHash,
619
880
  Anthropic::ToolBash20250124::OrHash,
620
881
  Anthropic::ToolTextEditor20250124::OrHash,
882
+ Anthropic::ToolTextEditor20250429::OrHash,
883
+ Anthropic::ToolTextEditor20250728::OrHash,
621
884
  Anthropic::WebSearchTool20250305::OrHash
622
885
  )
623
886
  ],
@@ -682,37 +945,14 @@ module Anthropic
682
945
  # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
683
946
  # ```
684
947
  #
685
- # Starting with Claude 3 models, you can also send image content blocks:
686
- #
687
- # ```json
688
- # {
689
- # "role": "user",
690
- # "content": [
691
- # {
692
- # "type": "image",
693
- # "source": {
694
- # "type": "base64",
695
- # "media_type": "image/jpeg",
696
- # "data": "/9j/4AAQSkZJRg..."
697
- # }
698
- # },
699
- # { "type": "text", "text": "What is in this image?" }
700
- # ]
701
- # }
702
- # ```
703
- #
704
- # We currently support the `base64` source type for images, and the `image/jpeg`,
705
- # `image/png`, `image/gif`, and `image/webp` media types.
706
- #
707
- # See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
708
- # more input examples.
948
+ # See [input examples](https://docs.anthropic.com/en/api/messages-examples).
709
949
  #
710
950
  # Note that if you want to include a
711
951
  # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
712
952
  # the top-level `system` parameter — there is no `"system"` role for input
713
953
  # messages in the Messages API.
714
954
  #
715
- # There is a limit of 100000 messages in a single request.
955
+ # There is a limit of 100,000 messages in a single request.
716
956
  messages:,
717
957
  # The model that will complete your prompt.\n\nSee
718
958
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -744,6 +984,12 @@ module Anthropic
744
984
  # those tools using the tool input generated by the model and then optionally
745
985
  # return results back to the model using `tool_result` content blocks.
746
986
  #
987
+ # There are two types of tools: **client tools** and **server tools**. The
988
+ # behavior described below applies to client tools. For
989
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
990
+ # see their individual documentation as each has its own behavior (e.g., the
991
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
992
+ #
747
993
  # Each tool definition includes:
748
994
  #
749
995
  # - `name`: Name of the tool.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ Streaming = Anthropic::Helpers::Streaming
5
+ end
@@ -5,6 +5,15 @@ module Anthropic
5
5
  end
6
6
 
7
7
  class ConversionError < Anthropic::Errors::Error
8
+ def cause: -> StandardError?
9
+
10
+ def initialize: (
11
+ on: Class,
12
+ method: Symbol,
13
+ target: top,
14
+ value: top,
15
+ ?cause: StandardError?
16
+ ) -> void
8
17
  end
9
18
 
10
19
  class APIError < Anthropic::Errors::Error
@@ -0,0 +1,117 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Streaming
4
+ type text_event = { type: :text, text: String, snapshot: String }
5
+
6
+ class TextEvent < Anthropic::Internal::Type::BaseModel
7
+ attr_accessor type: :text
8
+
9
+ attr_accessor text: String
10
+
11
+ attr_accessor snapshot: String
12
+
13
+ def initialize: (text: String, snapshot: String, ?type: :text) -> void
14
+ end
15
+
16
+ type citation_event =
17
+ {
18
+ type: :citation,
19
+ citation: Anthropic::Models::CitationsDelta::citation,
20
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
21
+ }
22
+
23
+ class CitationEvent < Anthropic::Internal::Type::BaseModel
24
+ attr_accessor type: :citation
25
+
26
+ attr_accessor citation: Anthropic::Models::CitationsDelta::citation
27
+
28
+ attr_accessor snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
29
+
30
+ def initialize: (
31
+ citation: Anthropic::Models::CitationsDelta::citation,
32
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation],
33
+ ?type: :citation
34
+ ) -> void
35
+ end
36
+
37
+ type thinking_event =
38
+ { type: :thinking, thinking: String, snapshot: String }
39
+
40
+ class ThinkingEvent < Anthropic::Internal::Type::BaseModel
41
+ attr_accessor type: :thinking
42
+
43
+ attr_accessor thinking: String
44
+
45
+ attr_accessor snapshot: String
46
+
47
+ def initialize: (
48
+ thinking: String,
49
+ snapshot: String,
50
+ ?type: :thinking
51
+ ) -> void
52
+ end
53
+
54
+ type signature_event = { type: :signature, signature: String }
55
+
56
+ class SignatureEvent < Anthropic::Internal::Type::BaseModel
57
+ attr_accessor type: :signature
58
+
59
+ attr_accessor signature: String
60
+
61
+ def initialize: (signature: String, ?type: :signature) -> void
62
+ end
63
+
64
+ type input_json_event =
65
+ { type: :input_json, partial_json: String, snapshot: untyped }
66
+
67
+ class InputJsonEvent < Anthropic::Internal::Type::BaseModel
68
+ attr_accessor type: :input_json
69
+
70
+ attr_accessor partial_json: String
71
+
72
+ attr_accessor snapshot: untyped
73
+
74
+ def initialize: (
75
+ partial_json: String,
76
+ snapshot: untyped,
77
+ ?type: :input_json
78
+ ) -> void
79
+ end
80
+
81
+ type message_stop_event =
82
+ { type: :message_stop, message: Anthropic::Models::message }
83
+
84
+ class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
85
+ attr_accessor type: :message_stop
86
+
87
+ attr_accessor message: Anthropic::Models::message
88
+
89
+ def initialize: (
90
+ message: Anthropic::Models::message,
91
+ ?type: :message_stop
92
+ ) -> void
93
+ end
94
+
95
+ type content_block_stop_event =
96
+ {
97
+ type: :content_block_stop,
98
+ index: Integer,
99
+ content_block: Anthropic::Models::content_block
100
+ }
101
+
102
+ class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
103
+ attr_accessor type: :content_block_stop
104
+
105
+ attr_accessor index: Integer
106
+
107
+ attr_accessor content_block: Anthropic::Models::content_block
108
+
109
+ def initialize: (
110
+ index: Integer,
111
+ content_block: Anthropic::Models::content_block,
112
+ ?type: :content_block_stop
113
+ ) -> void
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,57 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Streaming
4
+ type raw_message_event =
5
+ Anthropic::Models::raw_message_start_event
6
+ | Anthropic::Models::raw_message_delta_event
7
+ | Anthropic::Models::raw_message_stop_event
8
+ | Anthropic::Models::raw_content_block_start_event
9
+ | Anthropic::Models::raw_content_block_delta_event
10
+ | Anthropic::Models::raw_content_block_stop_event
11
+
12
+ type stream_event =
13
+ raw_message_event
14
+ | text_event
15
+ | citation_event
16
+ | thinking_event
17
+ | signature_event
18
+ | input_json_event
19
+ | message_stop_event
20
+ | content_block_stop_event
21
+
22
+ class MessageStream
23
+ include Anthropic::Internal::Type::BaseStream[raw_message_event, stream_event]
24
+
25
+ @raw_stream: Anthropic::Internal::Stream[raw_message_event]
26
+ @accumated_message_snapshot: Anthropic::Models::message?
27
+ @iterator: Enumerable[stream_event]?
28
+
29
+ def initialize: (
30
+ raw_stream: Anthropic::Internal::Stream[raw_message_event]
31
+ ) -> void
32
+
33
+ def until_done: -> void
34
+
35
+ def text: -> Enumerator[String]
36
+
37
+ def accumulated_message: -> Anthropic::Models::message
38
+
39
+ def accumulated_text: -> String
40
+
41
+ private
42
+
43
+ def iterator: -> Enumerable[stream_event]
44
+
45
+ def accumulate_event: (
46
+ event: raw_message_event,
47
+ current_snapshot: Anthropic::Models::message?
48
+ ) -> Anthropic::Models::message
49
+
50
+ def build_events: (
51
+ event: raw_message_event,
52
+ message_snapshot: Anthropic::Models::message
53
+ ) -> ::Array[stream_event]
54
+ end
55
+ end
56
+ end
57
+ end
@@ -99,7 +99,7 @@ module Anthropic
99
99
  retry_count: Integer
100
100
  ) -> Float
101
101
 
102
- private def send_request: (
102
+ def send_request: (
103
103
  Anthropic::Internal::Transport::BaseClient::request_input request,
104
104
  redirect_count: Integer,
105
105
  retry_count: Integer,
@@ -23,6 +23,10 @@ module Anthropic
23
23
  url: URI::Generic,
24
24
  status: Integer,
25
25
  response: top,
26
+ unwrap: Symbol
27
+ | Integer
28
+ | ::Array[Symbol | Integer]
29
+ | ^(top arg0) -> top,
26
30
  stream: Enumerable[Message]
27
31
  ) -> void
28
32