anthropic 1.12.0 → 1.14.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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +31 -1
  4. data/lib/anthropic/helpers/input_schema/base_model.rb +6 -3
  5. data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +9 -3
  6. data/lib/anthropic/helpers/input_schema/supported_schemas.rb +106 -0
  7. data/lib/anthropic/helpers/input_schema/union_of.rb +3 -1
  8. data/lib/anthropic/helpers/messages.rb +107 -0
  9. data/lib/anthropic/helpers/streaming/message_stream.rb +57 -43
  10. data/lib/anthropic/helpers/tools/base_tool.rb +82 -0
  11. data/lib/anthropic/helpers/tools/runner.rb +156 -0
  12. data/lib/anthropic/helpers/tools.rb +5 -0
  13. data/lib/anthropic/internal/transport/base_client.rb +7 -1
  14. data/lib/anthropic/internal/transport/pooled_net_requester.rb +36 -26
  15. data/lib/anthropic/models/beta/beta_all_thinking_turns.rb +19 -0
  16. data/lib/anthropic/models/beta/beta_clear_thinking_20251015_edit.rb +48 -0
  17. data/lib/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rb +36 -0
  18. data/lib/anthropic/models/beta/beta_context_management_config.rb +17 -3
  19. data/lib/anthropic/models/beta/beta_context_management_response.rb +16 -3
  20. data/lib/anthropic/models/beta/beta_mcp_tool_use_block_param.rb +3 -3
  21. data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +3 -3
  22. data/lib/anthropic/models/beta/beta_thinking_turns.rb +25 -0
  23. data/lib/anthropic/models/beta/beta_tool.rb +5 -3
  24. data/lib/anthropic/models/beta/beta_tool_use_block.rb +14 -0
  25. data/lib/anthropic/models/beta/beta_tool_use_block_param.rb +3 -3
  26. data/lib/anthropic/models/model.rb +6 -20
  27. data/lib/anthropic/models/server_tool_use_block_param.rb +3 -3
  28. data/lib/anthropic/models/tool.rb +5 -3
  29. data/lib/anthropic/models/tool_use_block.rb +6 -6
  30. data/lib/anthropic/models/tool_use_block_param.rb +3 -3
  31. data/lib/anthropic/resources/beta/messages.rb +23 -5
  32. data/lib/anthropic/resources/messages.rb +7 -81
  33. data/lib/anthropic/version.rb +1 -1
  34. data/lib/anthropic.rb +19 -10
  35. data/manifest.yaml +1 -0
  36. data/rbi/anthropic/helpers/input_schema/base_model.rbi +7 -2
  37. data/rbi/anthropic/helpers/tools/base_tool.rbi +51 -0
  38. data/rbi/anthropic/helpers/tools/runner.rbi +40 -0
  39. data/rbi/anthropic/helpers/tools.rbi +5 -0
  40. data/rbi/anthropic/internal/transport/base_client.rbi +5 -0
  41. data/rbi/anthropic/internal/transport/pooled_net_requester.rbi +6 -2
  42. data/rbi/anthropic/internal/type/base_model.rbi +8 -4
  43. data/rbi/anthropic/models/beta/beta_all_thinking_turns.rbi +30 -0
  44. data/rbi/anthropic/models/beta/beta_clear_thinking_20251015_edit.rbi +109 -0
  45. data/rbi/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rbi +61 -0
  46. data/rbi/anthropic/models/beta/beta_context_management_config.rbi +51 -4
  47. data/rbi/anthropic/models/beta/beta_context_management_response.rbi +32 -3
  48. data/rbi/anthropic/models/beta/beta_mcp_tool_use_block.rbi +3 -3
  49. data/rbi/anthropic/models/beta/beta_mcp_tool_use_block_param.rbi +3 -3
  50. data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +3 -3
  51. data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +3 -3
  52. data/rbi/anthropic/models/beta/beta_thinking_turns.rbi +33 -0
  53. data/rbi/anthropic/models/beta/beta_tool.rbi +3 -3
  54. data/rbi/anthropic/models/beta/beta_tool_use_block.rbi +8 -3
  55. data/rbi/anthropic/models/beta/beta_tool_use_block_param.rbi +3 -3
  56. data/rbi/anthropic/models/model.rbi +0 -11
  57. data/rbi/anthropic/models/server_tool_use_block.rbi +8 -3
  58. data/rbi/anthropic/models/server_tool_use_block_param.rbi +3 -3
  59. data/rbi/anthropic/models/tool.rbi +3 -3
  60. data/rbi/anthropic/models/tool_use_block.rbi +11 -3
  61. data/rbi/anthropic/models/tool_use_block_param.rbi +3 -3
  62. data/rbi/anthropic/resources/beta/messages.rbi +296 -0
  63. data/sig/anthropic/internal/transport/base_client.rbs +2 -0
  64. data/sig/anthropic/internal/transport/pooled_net_requester.rbs +4 -1
  65. data/sig/anthropic/models/beta/beta_all_thinking_turns.rbs +17 -0
  66. data/sig/anthropic/models/beta/beta_clear_thinking_20251015_edit.rbs +44 -0
  67. data/sig/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rbs +34 -0
  68. data/sig/anthropic/models/beta/beta_context_management_config.rbs +18 -6
  69. data/sig/anthropic/models/beta/beta_context_management_response.rbs +14 -4
  70. data/sig/anthropic/models/beta/beta_mcp_tool_use_block.rbs +4 -4
  71. data/sig/anthropic/models/beta/beta_mcp_tool_use_block_param.rbs +4 -4
  72. data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +4 -4
  73. data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +4 -4
  74. data/sig/anthropic/models/beta/beta_thinking_turns.rbs +19 -0
  75. data/sig/anthropic/models/beta/beta_tool.rbs +8 -4
  76. data/sig/anthropic/models/beta/beta_tool_use_block.rbs +9 -4
  77. data/sig/anthropic/models/beta/beta_tool_use_block_param.rbs +4 -4
  78. data/sig/anthropic/models/model.rbs +0 -11
  79. data/sig/anthropic/models/server_tool_use_block.rbs +9 -4
  80. data/sig/anthropic/models/server_tool_use_block_param.rbs +4 -4
  81. data/sig/anthropic/models/tool.rbs +8 -4
  82. data/sig/anthropic/models/tool_use_block.rbs +9 -4
  83. data/sig/anthropic/models/tool_use_block_param.rbs +4 -4
  84. metadata +23 -4
  85. data/lib/anthropic/helpers/input_schema/property_mapping.rb +0 -47
  86. /data/rbi/anthropic/helpers/{structured_output.rbi → input_schema.rbi} +0 -0
@@ -30,12 +30,6 @@ module Anthropic
30
30
 
31
31
  variant const: -> { Anthropic::Models::Model::CLAUDE_SONNET_4_5_20250929 }
32
32
 
33
- variant const: -> { Anthropic::Models::Model::CLAUDE_3_5_SONNET_LATEST }
34
-
35
- variant const: -> { Anthropic::Models::Model::CLAUDE_3_5_SONNET_20241022 }
36
-
37
- variant const: -> { Anthropic::Models::Model::CLAUDE_3_5_SONNET_20240620 }
38
-
39
33
  variant const: -> { Anthropic::Models::Model::CLAUDE_OPUS_4_0 }
40
34
 
41
35
  variant const: -> { Anthropic::Models::Model::CLAUDE_OPUS_4_20250514 }
@@ -62,9 +56,15 @@ module Anthropic
62
56
  # @!group
63
57
 
64
58
  # High-performance model with early extended thinking
59
+ # @deprecated Will reach end-of-life on February 19th, 2026. Please migrate to a newer model.
60
+ # Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
61
+ # information.
65
62
  CLAUDE_3_7_SONNET_LATEST = :"claude-3-7-sonnet-latest"
66
63
 
67
64
  # High-performance model with early extended thinking
65
+ # @deprecated Will reach end-of-life on February 19th, 2026. Please migrate to a newer model.
66
+ # Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
67
+ # information.
68
68
  CLAUDE_3_7_SONNET_20250219 = :"claude-3-7-sonnet-20250219"
69
69
 
70
70
  # Fastest and most compact model for near-instant responsiveness
@@ -94,20 +94,6 @@ module Anthropic
94
94
  # Our best model for real-world agents and coding
95
95
  CLAUDE_SONNET_4_5_20250929 = :"claude-sonnet-4-5-20250929"
96
96
 
97
- # Our previous most intelligent model
98
- CLAUDE_3_5_SONNET_LATEST = :"claude-3-5-sonnet-latest"
99
-
100
- # Our previous most intelligent model
101
- # @deprecated Will reach end-of-life on October 22, 2025. Please migrate to a newer model.
102
- # Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
103
- # information.
104
- CLAUDE_3_5_SONNET_20241022 = :"claude-3-5-sonnet-20241022"
105
-
106
- # @deprecated Will reach end-of-life on October 22, 2025. Please migrate to a newer model.
107
- # Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more
108
- # information.
109
- CLAUDE_3_5_SONNET_20240620 = :"claude-3-5-sonnet-20240620"
110
-
111
97
  # Our most capable model
112
98
  CLAUDE_OPUS_4_0 = :"claude-opus-4-0"
113
99
 
@@ -10,8 +10,8 @@ module Anthropic
10
10
 
11
11
  # @!attribute input
12
12
  #
13
- # @return [Object]
14
- required :input, Anthropic::Internal::Type::Unknown
13
+ # @return [Hash{Symbol=>Object}]
14
+ required :input, Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown]
15
15
 
16
16
  # @!attribute name
17
17
  #
@@ -32,7 +32,7 @@ module Anthropic
32
32
  # @!method initialize(id:, input:, cache_control: nil, name: :web_search, type: :server_tool_use)
33
33
  # @param id [String]
34
34
  #
35
- # @param input [Object]
35
+ # @param input [Hash{Symbol=>Object}]
36
36
  #
37
37
  # @param cache_control [Anthropic::Models::CacheControlEphemeral, nil] Create a cache control breakpoint at this content block.
38
38
  #
@@ -65,8 +65,10 @@ module Anthropic
65
65
 
66
66
  # @!attribute properties
67
67
  #
68
- # @return [Object, nil]
69
- optional :properties, Anthropic::Internal::Type::Unknown, nil?: true
68
+ # @return [Hash{Symbol=>Object}, nil]
69
+ optional :properties,
70
+ Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown],
71
+ nil?: true
70
72
 
71
73
  # @!attribute required
72
74
  #
@@ -79,7 +81,7 @@ module Anthropic
79
81
  # This defines the shape of the `input` that your tool accepts and that the model
80
82
  # will produce.
81
83
  #
82
- # @param properties [Object, nil]
84
+ # @param properties [Hash{Symbol=>Object}, nil]
83
85
  # @param required [Array<String>, nil]
84
86
  # @param type [Symbol, :object]
85
87
  end
@@ -23,18 +23,18 @@ module Anthropic
23
23
  # @return [Symbol, :tool_use]
24
24
  required :type, const: :tool_use
25
25
 
26
- # @api private
27
- #
28
- # Internal buffer for accumulating partial JSON during streaming.
29
- # Used by streaming helpers to reconstruct complete JSON input from deltas.
30
- optional :json_buf, String
31
-
32
26
  response_only do
33
27
  # @api public
34
28
  #
35
29
  # Parsed input data coerced to the tool's input schema model.
36
30
  # Only present when tools are defined using the InputSchema DSL.
37
31
  optional :parsed, Anthropic::Internal::Type::Unknown
32
+
33
+ # @api private
34
+ #
35
+ # Internal buffer for accumulating partial JSON during streaming.
36
+ # Used by streaming helpers to reconstruct complete JSON input from deltas.
37
+ optional :_json_buf, String
38
38
  end
39
39
 
40
40
  # @!method initialize(id:, input:, name:, type: :tool_use)
@@ -10,8 +10,8 @@ module Anthropic
10
10
 
11
11
  # @!attribute input
12
12
  #
13
- # @return [Object]
14
- required :input, Anthropic::Internal::Type::Unknown
13
+ # @return [Hash{Symbol=>Object}]
14
+ required :input, Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown]
15
15
 
16
16
  # @!attribute name
17
17
  #
@@ -32,7 +32,7 @@ module Anthropic
32
32
  # @!method initialize(id:, input:, name:, cache_control: nil, type: :tool_use)
33
33
  # @param id [String]
34
34
  #
35
- # @param input [Object]
35
+ # @param input [Hash{Symbol=>Object}]
36
36
  #
37
37
  # @param name [String]
38
38
  #
@@ -7,6 +7,13 @@ module Anthropic
7
7
  # @return [Anthropic::Resources::Beta::Messages::Batches]
8
8
  attr_reader :batches
9
9
 
10
+ # @param params [Anthropic::Models::Beta::MessageCreateParams]
11
+ #
12
+ # @return [Anthropic::Helpers::Tools::Runner]
13
+ def tool_runner(params)
14
+ Anthropic::Helpers::Tools::Runner.new(@client, params:)
15
+ end
16
+
10
17
  # See {Anthropic::Resources::Beta::Messages#stream_raw} for streaming counterpart.
11
18
  #
12
19
  # Some parameter documentations has been truncated, see
@@ -68,8 +75,12 @@ module Anthropic
68
75
  raise ArgumentError.new(message)
69
76
  end
70
77
 
78
+ tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(parsed, strict: nil)
79
+
80
+ unwrap = ->(raw) { Anthropic::Helpers::Messages.parse_input_schemas!(raw, tools:, models:) }
81
+
71
82
  if options.empty? && @client.timeout == Anthropic::Client::DEFAULT_TIMEOUT_IN_SECONDS
72
- model = parsed[:model].to_sym
83
+ model = parsed[:model]&.to_sym
73
84
  max_tokens = parsed[:max_tokens].to_i
74
85
  timeout = @client.calculate_nonstreaming_timeout(
75
86
  max_tokens,
@@ -87,6 +98,7 @@ module Anthropic
87
98
  headers: parsed.slice(*header_params.keys).transform_keys(header_params),
88
99
  body: parsed.except(*header_params.keys),
89
100
  model: Anthropic::Beta::BetaMessage,
101
+ unwrap: unwrap,
90
102
  options: options
91
103
  )
92
104
  end
@@ -152,16 +164,22 @@ module Anthropic
152
164
  raise ArgumentError.new(message)
153
165
  end
154
166
  parsed.store(:stream, true)
167
+ tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(parsed, strict: nil)
168
+
169
+ header_params = {betas: "anthropic-beta"}
155
170
  raw_stream = @client.request(
156
171
  method: :post,
157
172
  path: "v1/messages?beta=true",
158
- headers: {"accept" => "text/event-stream"},
159
- body: parsed,
173
+ headers: {
174
+ "accept" => "text/event-stream",
175
+ **parsed.slice(*header_params.keys)
176
+ }.transform_keys(header_params),
177
+ body: parsed.except(*header_params.keys),
160
178
  stream: Anthropic::Internal::Stream,
161
179
  model: Anthropic::Beta::BetaRawMessageStreamEvent,
162
- options: options
180
+ options: {timeout: 600, **options}
163
181
  )
164
- Anthropic::Streaming::MessageStream.new(raw_stream: raw_stream)
182
+ Anthropic::Streaming::MessageStream.new(raw_stream:, tools:, models:)
165
183
  end
166
184
 
167
185
  # See {Anthropic::Resources::Beta::Messages#create} for non-streaming counterpart.
@@ -59,14 +59,12 @@ module Anthropic
59
59
  raise ArgumentError.new(message)
60
60
  end
61
61
 
62
- tool_models = get_structured_output_models(parsed)
62
+ tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(parsed, strict: nil)
63
63
 
64
- unwrap = if tool_models.any?
65
- ->(raw) { parse_structured_outputs!(raw, tool_models) }
66
- end
64
+ unwrap = ->(raw) { Anthropic::Helpers::Messages.parse_input_schemas!(raw, tools:, models:) }
67
65
 
68
66
  if options.empty? && @client.timeout == Anthropic::Client::DEFAULT_TIMEOUT_IN_SECONDS
69
- model = parsed[:model].to_sym
67
+ model = parsed[:model]&.to_sym
70
68
  max_tokens = parsed[:max_tokens].to_i
71
69
  timeout = @client.calculate_nonstreaming_timeout(
72
70
  max_tokens,
@@ -87,6 +85,8 @@ module Anthropic
87
85
  )
88
86
  end
89
87
 
88
+ alias_method :parse, :create
89
+
90
90
  # See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
91
91
  #
92
92
  # Some parameter documentations has been truncated, see
@@ -141,7 +141,7 @@ module Anthropic
141
141
  end
142
142
  parsed.store(:stream, true)
143
143
 
144
- tool_models = get_structured_output_models(parsed)
144
+ tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(parsed, strict: nil)
145
145
 
146
146
  raw_stream = @client.request(
147
147
  method: :post,
@@ -152,10 +152,7 @@ module Anthropic
152
152
  model: Anthropic::Models::RawMessageStreamEvent,
153
153
  options: options
154
154
  )
155
- Anthropic::Streaming::MessageStream.new(
156
- raw_stream: raw_stream,
157
- tool_models: tool_models
158
- )
155
+ Anthropic::Streaming::MessageStream.new(raw_stream:, tools:, models:)
159
156
  end
160
157
 
161
158
  # See {Anthropic::Resources::Messages#create} for non-streaming counterpart.
@@ -270,77 +267,6 @@ module Anthropic
270
267
  @client = client
271
268
  @batches = Anthropic::Resources::Messages::Batches.new(client: client)
272
269
  end
273
-
274
- private
275
-
276
- # Extract tool models from the request and convert them to JSON Schema
277
- # Returns a hash mapping tool name to Ruby model.
278
- def get_structured_output_models(parsed)
279
- tool_models = {}
280
-
281
- case parsed
282
- in {tools: Array => tools}
283
- mapped = tools.map do |tool|
284
- case tool
285
- # Direct tool class:
286
- in Anthropic::Helpers::InputSchema::JsonSchemaConverter
287
- name = tool.name.split("::").last
288
- description = extract_class_description(tool)
289
- tool_models.store(name, tool)
290
- {
291
- name: name,
292
- description: description,
293
- input_schema: tool.to_json_schema
294
- }
295
- # Tool with explicit name/description and BaseModel as input_schema:
296
- in {name: String => name,
297
- input_schema: Anthropic::Helpers::InputSchema::JsonSchemaConverter => model,
298
- **rest}
299
- tool_models.store(name, model)
300
- rest.merge(
301
- name: name,
302
- input_schema: model.to_json_schema
303
- )
304
- else
305
- # Any other format (pass through unchanged)
306
- # This includes raw JSON schemas and any other tool definitions.
307
- tool
308
- end
309
- end
310
- tools.replace(mapped)
311
- else
312
- end
313
-
314
- tool_models
315
- end
316
-
317
- # Extract class description from a BaseModel class
318
- def extract_class_description(klass)
319
- klass.respond_to?(:doc_string) ? klass.doc_string : nil
320
- end
321
-
322
- def parse_structured_outputs!(raw, tool_models)
323
- return raw if tool_models.empty?
324
-
325
- raw[:content]&.each do |content|
326
- next unless content[:type] == "tool_use"
327
-
328
- model = tool_models[content[:name]]
329
- next unless model
330
-
331
- begin
332
- parsed_input = content[:input]
333
-
334
- coerced = Anthropic::Internal::Type::Converter.coerce(model, parsed_input)
335
-
336
- content.store(:parsed, coerced)
337
- rescue StandardError => e
338
- content.store(:parsed, {error: e.message})
339
- end
340
- end
341
-
342
- raw
343
- end
344
270
  end
345
271
  end
346
272
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anthropic
4
- VERSION = "1.12.0"
4
+ VERSION = "1.14.0"
5
5
  end
data/lib/anthropic.rb CHANGED
@@ -9,6 +9,7 @@ require "erb"
9
9
  require "etc"
10
10
  require "json"
11
11
  require "net/http"
12
+ require "openssl"
12
13
  require "pathname"
13
14
  require "rbconfig"
14
15
  require "securerandom"
@@ -55,6 +56,17 @@ require_relative "anthropic/helpers/bedrock/client"
55
56
  require_relative "anthropic/helpers/vertex/client"
56
57
  require_relative "anthropic/bedrock"
57
58
  require_relative "anthropic/vertex"
59
+ require_relative "anthropic/helpers/input_schema"
60
+ require_relative "anthropic/helpers/input_schema/supported_schemas"
61
+ require_relative "anthropic/helpers/input_schema/json_schema_converter"
62
+ require_relative "anthropic/helpers/input_schema/base_model"
63
+ require_relative "anthropic/helpers/input_schema/array_of"
64
+ require_relative "anthropic/helpers/input_schema/boolean"
65
+ require_relative "anthropic/helpers/input_schema/enum_of"
66
+ require_relative "anthropic/helpers/input_schema/union_of"
67
+ require_relative "anthropic/helpers/input_schema/parsed_json"
68
+ require_relative "anthropic/input_schema"
69
+ require_relative "anthropic/helpers/messages"
58
70
  require_relative "anthropic/internal/stream"
59
71
  require_relative "anthropic/internal/jsonl_stream"
60
72
  require_relative "anthropic/internal/page"
@@ -66,6 +78,7 @@ require_relative "anthropic/models/api_error_object"
66
78
  require_relative "anthropic/models/authentication_error"
67
79
  require_relative "anthropic/models/base64_image_source"
68
80
  require_relative "anthropic/models/base64_pdf_source"
81
+ require_relative "anthropic/models/beta/beta_all_thinking_turns"
69
82
  require_relative "anthropic/models/beta/beta_base64_image_source"
70
83
  require_relative "anthropic/models/beta/beta_base64_pdf_block"
71
84
  require_relative "anthropic/models/beta/beta_base64_pdf_source"
@@ -92,6 +105,8 @@ require_relative "anthropic/models/beta/beta_citation_search_result_location"
92
105
  require_relative "anthropic/models/beta/beta_citation_search_result_location_param"
93
106
  require_relative "anthropic/models/beta/beta_citations_web_search_result_location"
94
107
  require_relative "anthropic/models/beta/beta_citation_web_search_result_location_param"
108
+ require_relative "anthropic/models/beta/beta_clear_thinking_20251015_edit"
109
+ require_relative "anthropic/models/beta/beta_clear_thinking_20251015_edit_response"
95
110
  require_relative "anthropic/models/beta/beta_clear_tool_uses_20250919_edit"
96
111
  require_relative "anthropic/models/beta/beta_clear_tool_uses_20250919_edit_response"
97
112
  require_relative "anthropic/models/beta/beta_code_execution_output_block"
@@ -185,6 +200,7 @@ require_relative "anthropic/models/beta/beta_thinking_config_disabled"
185
200
  require_relative "anthropic/models/beta/beta_thinking_config_enabled"
186
201
  require_relative "anthropic/models/beta/beta_thinking_config_param"
187
202
  require_relative "anthropic/models/beta/beta_thinking_delta"
203
+ require_relative "anthropic/models/beta/beta_thinking_turns"
188
204
  require_relative "anthropic/models/beta/beta_tool"
189
205
  require_relative "anthropic/models/beta/beta_tool_bash_20241022"
190
206
  require_relative "anthropic/models/beta/beta_tool_bash_20250124"
@@ -408,13 +424,6 @@ require_relative "anthropic/resources/completions"
408
424
  require_relative "anthropic/resources/messages"
409
425
  require_relative "anthropic/resources/messages/batches"
410
426
  require_relative "anthropic/resources/models"
411
- require_relative "anthropic/helpers/input_schema"
412
- require_relative "anthropic/helpers/input_schema/property_mapping"
413
- require_relative "anthropic/helpers/input_schema/json_schema_converter"
414
- require_relative "anthropic/helpers/input_schema/base_model"
415
- require_relative "anthropic/helpers/input_schema/array_of"
416
- require_relative "anthropic/helpers/input_schema/boolean"
417
- require_relative "anthropic/helpers/input_schema/enum_of"
418
- require_relative "anthropic/helpers/input_schema/union_of"
419
- require_relative "anthropic/helpers/input_schema/parsed_json"
420
- require_relative "anthropic/input_schema"
427
+ require_relative "anthropic/helpers/tools/runner"
428
+ require_relative "anthropic/helpers/tools/base_tool"
429
+ require_relative "anthropic/helpers/tools"
data/manifest.yaml CHANGED
@@ -6,6 +6,7 @@ dependencies:
6
6
  - etc
7
7
  - json
8
8
  - net/http
9
+ - openssl
9
10
  - pathname
10
11
  - rbconfig
11
12
  - securerandom
@@ -12,8 +12,13 @@ module Anthropic
12
12
  extend Anthropic::Helpers::InputSchema::JsonSchemaConverter
13
13
 
14
14
  class << self
15
- sig { params(doc: T.nilable(String)).void }
16
- attr_writer :doc
15
+ # @api public
16
+ #
17
+ sig { params(description: String).returns(T.class_of(String)) }
18
+ def description(description)
19
+ end
20
+
21
+ alias_method :doc, :description
17
22
  end
18
23
  end
19
24
  end
@@ -0,0 +1,51 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Helpers
5
+ module Tools
6
+ # @api private
7
+ #
8
+ class BaseTool
9
+ include Anthropic::Internal::Type::Converter
10
+ include Anthropic::Helpers::InputSchema::JsonSchemaConverter
11
+
12
+ class << self
13
+ # @api public
14
+ #
15
+ sig { returns(T.class_of(Anthropic::Helpers::InputSchema::BaseModel)) }
16
+ attr_reader :model
17
+
18
+ sig { returns(T.class_of(String)) }
19
+ attr_reader :doc_string
20
+
21
+ # @api public
22
+ #
23
+ sig { params(description: String).returns(T.class_of(String)) }
24
+ def description(description)
25
+ end
26
+
27
+ alias_method :doc, :description
28
+
29
+ # @api public
30
+ #
31
+ sig { params(model: T.class_of(Anthropic::Helpers::InputSchema::BaseModel)).returns(T.class_of(Anthropic::Helpers::InputSchema::BaseModel)) }
32
+ def input_schema(model) = (@model = model)
33
+ end
34
+
35
+ # @api public
36
+ #
37
+ # Override the `#parse` method to customize the pre-processing of the tool call argument
38
+ #
39
+ sig { params(value: T.anything).returns(T.anything) }
40
+ def parse(value)
41
+ end
42
+
43
+ # @api public
44
+ #
45
+ sig { params(parsed: Anthropic::Helpers::InputSchema::BaseModel).returns(T.anything) }
46
+ def call(parsed)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,40 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Helpers
5
+ module Tools
6
+ # @api private
7
+ #
8
+ class Runner
9
+ sig { returns(Anthropic::Models::Beta::MessageCreateParams) }
10
+ attr_accessor :params
11
+
12
+ sig { returns(T::Boolean) }
13
+ def finished?; end
14
+
15
+ sig { params(messages: Anthropic::Models::Beta::BetaMessageParam).void }
16
+ def feed_messages(*messages); end
17
+
18
+ sig { returns(Anthropic::Models::BetaMessage) }
19
+ def next_message; end
20
+
21
+ sig { returns(T::Array[Anthropic::Models::BetaMessage]) }
22
+ def run_until_finished; end
23
+
24
+ sig do
25
+ params(
26
+ blk: T.proc.params(arg0: Anthropic::Models::BetaMessage).void
27
+ ).void
28
+ end
29
+ def each_message(&blk); end
30
+
31
+ sig do
32
+ params(
33
+ blk: T.proc.params(arg0: Anthropic::Streaming::MessageStream).void
34
+ ).void
35
+ end
36
+ def each_streaming(&blk); end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ BaseTool = Anthropic::Helpers::Tools::BaseTool
5
+ end
@@ -184,6 +184,11 @@ module Anthropic
184
184
  private def auth_headers
185
185
  end
186
186
 
187
+ # @api private
188
+ sig { returns(String) }
189
+ private def user_agent
190
+ end
191
+
187
192
  # @api private
188
193
  sig { returns(String) }
189
194
  private def generate_idempotency_key
@@ -26,8 +26,12 @@ module Anthropic
26
26
 
27
27
  class << self
28
28
  # @api private
29
- sig { params(url: URI::Generic).returns(Net::HTTP) }
30
- def connect(url)
29
+ sig do
30
+ params(cert_store: OpenSSL::X509::Store, url: URI::Generic).returns(
31
+ Net::HTTP
32
+ )
33
+ end
34
+ def connect(cert_store:, url:)
31
35
  end
32
36
 
33
37
  # @api private
@@ -31,7 +31,7 @@ module Anthropic
31
31
  #
32
32
  # Assumes superclass fields are totally defined before fields are accessed /
33
33
  # defined on subclasses.
34
- sig { params(child: T.self_type).void }
34
+ sig { params(child: Anthropic::Internal::Type::BaseModel).void }
35
35
  def inherited(child)
36
36
  end
37
37
 
@@ -276,9 +276,13 @@ module Anthropic
276
276
 
277
277
  # Create a new instance of a model.
278
278
  sig do
279
- params(data: T.any(T::Hash[Symbol, T.anything], T.self_type)).returns(
280
- T.attached_class
281
- )
279
+ params(
280
+ data:
281
+ T.any(
282
+ T::Hash[Symbol, T.anything],
283
+ Anthropic::Internal::Type::BaseModel
284
+ )
285
+ ).returns(T.attached_class)
282
286
  end
283
287
  def self.new(data = {})
284
288
  end
@@ -0,0 +1,30 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Models
5
+ BetaAllThinkingTurns = Beta::BetaAllThinkingTurns
6
+
7
+ module Beta
8
+ class BetaAllThinkingTurns < Anthropic::Internal::Type::BaseModel
9
+ OrHash =
10
+ T.type_alias do
11
+ T.any(
12
+ Anthropic::Beta::BetaAllThinkingTurns,
13
+ Anthropic::Internal::AnyHash
14
+ )
15
+ end
16
+
17
+ sig { returns(Symbol) }
18
+ attr_accessor :type
19
+
20
+ sig { params(type: Symbol).returns(T.attached_class) }
21
+ def self.new(type: :all)
22
+ end
23
+
24
+ sig { override.returns({ type: Symbol }) }
25
+ def to_hash
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end