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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +31 -1
- data/lib/anthropic/helpers/input_schema/base_model.rb +6 -3
- data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +9 -3
- data/lib/anthropic/helpers/input_schema/supported_schemas.rb +106 -0
- data/lib/anthropic/helpers/input_schema/union_of.rb +3 -1
- data/lib/anthropic/helpers/messages.rb +107 -0
- data/lib/anthropic/helpers/streaming/message_stream.rb +57 -43
- data/lib/anthropic/helpers/tools/base_tool.rb +82 -0
- data/lib/anthropic/helpers/tools/runner.rb +156 -0
- data/lib/anthropic/helpers/tools.rb +5 -0
- data/lib/anthropic/internal/transport/base_client.rb +7 -1
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +36 -26
- data/lib/anthropic/models/beta/beta_all_thinking_turns.rb +19 -0
- data/lib/anthropic/models/beta/beta_clear_thinking_20251015_edit.rb +48 -0
- data/lib/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rb +36 -0
- data/lib/anthropic/models/beta/beta_context_management_config.rb +17 -3
- data/lib/anthropic/models/beta/beta_context_management_response.rb +16 -3
- data/lib/anthropic/models/beta/beta_mcp_tool_use_block_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_thinking_turns.rb +25 -0
- data/lib/anthropic/models/beta/beta_tool.rb +5 -3
- data/lib/anthropic/models/beta/beta_tool_use_block.rb +14 -0
- data/lib/anthropic/models/beta/beta_tool_use_block_param.rb +3 -3
- data/lib/anthropic/models/model.rb +6 -20
- data/lib/anthropic/models/server_tool_use_block_param.rb +3 -3
- data/lib/anthropic/models/tool.rb +5 -3
- data/lib/anthropic/models/tool_use_block.rb +6 -6
- data/lib/anthropic/models/tool_use_block_param.rb +3 -3
- data/lib/anthropic/resources/beta/messages.rb +23 -5
- data/lib/anthropic/resources/messages.rb +7 -81
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +19 -10
- data/manifest.yaml +1 -0
- data/rbi/anthropic/helpers/input_schema/base_model.rbi +7 -2
- data/rbi/anthropic/helpers/tools/base_tool.rbi +51 -0
- data/rbi/anthropic/helpers/tools/runner.rbi +40 -0
- data/rbi/anthropic/helpers/tools.rbi +5 -0
- data/rbi/anthropic/internal/transport/base_client.rbi +5 -0
- data/rbi/anthropic/internal/transport/pooled_net_requester.rbi +6 -2
- data/rbi/anthropic/internal/type/base_model.rbi +8 -4
- data/rbi/anthropic/models/beta/beta_all_thinking_turns.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_clear_thinking_20251015_edit.rbi +109 -0
- data/rbi/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rbi +61 -0
- data/rbi/anthropic/models/beta/beta_context_management_config.rbi +51 -4
- data/rbi/anthropic/models/beta/beta_context_management_response.rbi +32 -3
- data/rbi/anthropic/models/beta/beta_mcp_tool_use_block.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_mcp_tool_use_block_param.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_thinking_turns.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_tool.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_tool_use_block.rbi +8 -3
- data/rbi/anthropic/models/beta/beta_tool_use_block_param.rbi +3 -3
- data/rbi/anthropic/models/model.rbi +0 -11
- data/rbi/anthropic/models/server_tool_use_block.rbi +8 -3
- data/rbi/anthropic/models/server_tool_use_block_param.rbi +3 -3
- data/rbi/anthropic/models/tool.rbi +3 -3
- data/rbi/anthropic/models/tool_use_block.rbi +11 -3
- data/rbi/anthropic/models/tool_use_block_param.rbi +3 -3
- data/rbi/anthropic/resources/beta/messages.rbi +296 -0
- data/sig/anthropic/internal/transport/base_client.rbs +2 -0
- data/sig/anthropic/internal/transport/pooled_net_requester.rbs +4 -1
- data/sig/anthropic/models/beta/beta_all_thinking_turns.rbs +17 -0
- data/sig/anthropic/models/beta/beta_clear_thinking_20251015_edit.rbs +44 -0
- data/sig/anthropic/models/beta/beta_clear_thinking_20251015_edit_response.rbs +34 -0
- data/sig/anthropic/models/beta/beta_context_management_config.rbs +18 -6
- data/sig/anthropic/models/beta/beta_context_management_response.rbs +14 -4
- data/sig/anthropic/models/beta/beta_mcp_tool_use_block.rbs +4 -4
- data/sig/anthropic/models/beta/beta_mcp_tool_use_block_param.rbs +4 -4
- data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +4 -4
- data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +4 -4
- data/sig/anthropic/models/beta/beta_thinking_turns.rbs +19 -0
- data/sig/anthropic/models/beta/beta_tool.rbs +8 -4
- data/sig/anthropic/models/beta/beta_tool_use_block.rbs +9 -4
- data/sig/anthropic/models/beta/beta_tool_use_block_param.rbs +4 -4
- data/sig/anthropic/models/model.rbs +0 -11
- data/sig/anthropic/models/server_tool_use_block.rbs +9 -4
- data/sig/anthropic/models/server_tool_use_block_param.rbs +4 -4
- data/sig/anthropic/models/tool.rbs +8 -4
- data/sig/anthropic/models/tool_use_block.rbs +9 -4
- data/sig/anthropic/models/tool_use_block_param.rbs +4 -4
- metadata +23 -4
- data/lib/anthropic/helpers/input_schema/property_mapping.rb +0 -47
- /data/rbi/anthropic/helpers/{structured_output.rbi → input_schema.rbi} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Helpers
|
|
5
|
+
module Tools
|
|
6
|
+
class BaseTool
|
|
7
|
+
include Anthropic::Internal::Type::Converter
|
|
8
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
# @api public
|
|
12
|
+
#
|
|
13
|
+
# @return [Class<Anthropic::Helpers::InputSchema::BaseModel>]
|
|
14
|
+
attr_reader :model
|
|
15
|
+
|
|
16
|
+
# @return [String]
|
|
17
|
+
attr_reader :doc_string
|
|
18
|
+
|
|
19
|
+
# @api public
|
|
20
|
+
#
|
|
21
|
+
# @param description [String]
|
|
22
|
+
def description(description) = (@doc_string = description)
|
|
23
|
+
|
|
24
|
+
alias_method :doc, :description
|
|
25
|
+
|
|
26
|
+
# @api public
|
|
27
|
+
#
|
|
28
|
+
# @model [Class<Anthropic::Helpers::InputSchema::BaseModel>]
|
|
29
|
+
def input_schema(model) = (@model = model)
|
|
30
|
+
|
|
31
|
+
# @api private
|
|
32
|
+
#
|
|
33
|
+
# @param depth [Integer]
|
|
34
|
+
def inspect(depth: 0) = "#{name}[#{model.inspect(depth:)}]"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @api private
|
|
38
|
+
#
|
|
39
|
+
def to_json_schema_inner(state:) = self.class.model&.to_json_schema_inner(state:)
|
|
40
|
+
|
|
41
|
+
# @api private
|
|
42
|
+
#
|
|
43
|
+
def to_json_schema = self.class.model&.to_json_schema
|
|
44
|
+
|
|
45
|
+
# @api private
|
|
46
|
+
#
|
|
47
|
+
def dump(value, state:)
|
|
48
|
+
Anthropic::Internal::Type::Converter.dump(self.class.model, value, state:)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @api private
|
|
52
|
+
#
|
|
53
|
+
def coerce(value, state:)
|
|
54
|
+
parsed = parse(value)
|
|
55
|
+
Anthropic::Internal::Type::Converter.coerce(self.class.model, parsed, state:)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
|
59
|
+
|
|
60
|
+
# @api public
|
|
61
|
+
#
|
|
62
|
+
# Override the `#parse` method to customize the pre-processing of the tool call argument
|
|
63
|
+
#
|
|
64
|
+
# @param value [Object]
|
|
65
|
+
#
|
|
66
|
+
# @return [Object]
|
|
67
|
+
def parse(value) = value
|
|
68
|
+
|
|
69
|
+
# @api public
|
|
70
|
+
#
|
|
71
|
+
# @param parsed [Anthropic::Helpers::InputSchema::BaseModel]
|
|
72
|
+
def call(parsed) = raise NotImplementedError.new
|
|
73
|
+
|
|
74
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
|
75
|
+
|
|
76
|
+
# @api private
|
|
77
|
+
#
|
|
78
|
+
def inspect = "#<#{self.class.inspect(depth: 1)}:0x#{object_id.to_s(16)}>"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Helpers
|
|
5
|
+
module Tools
|
|
6
|
+
# @api private
|
|
7
|
+
#
|
|
8
|
+
class Runner
|
|
9
|
+
# @return [Anthropic::Models::Beta::MessageCreateParams]
|
|
10
|
+
attr_accessor :params
|
|
11
|
+
|
|
12
|
+
# @return [Boolean]
|
|
13
|
+
def finished? = @finished
|
|
14
|
+
|
|
15
|
+
# @param params [Array<Anthropic::Beta::BetaMessageParam>]
|
|
16
|
+
def feed_messages(*messages)
|
|
17
|
+
self.params = {**params.to_h, messages: params[:messages].to_a + messages}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [Array<Anthropic::Beta::BetaMessageParam>]
|
|
21
|
+
private def current_messages = params&.[](:messages).to_a
|
|
22
|
+
|
|
23
|
+
# @return [Anthropic::Models::BetaMessage, nil]
|
|
24
|
+
def next_message
|
|
25
|
+
message = nil
|
|
26
|
+
unless finished?
|
|
27
|
+
fold do
|
|
28
|
+
message = @client.beta.messages.create(_1)
|
|
29
|
+
[true, message]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
message
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Array<Anthropic::Models::BetaMessage>]
|
|
36
|
+
def run_until_finished
|
|
37
|
+
messages = []
|
|
38
|
+
each_streaming { messages << _1.accumulated_message }
|
|
39
|
+
messages
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @yieldparam [Anthropic::Models::BetaMessage]
|
|
43
|
+
def each_message(&blk)
|
|
44
|
+
unless block_given?
|
|
45
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
fold do
|
|
49
|
+
message = @client.beta.messages.create(_1)
|
|
50
|
+
blk.call(message)
|
|
51
|
+
[false, message]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @yieldparam [Anthropic::Internal::Stream<Anthropic::Models::Beta::BetaRawMessageStartEvent, Anthropic::Models::Beta::BetaRawMessageDeltaEvent, Anthropic::Models::Beta::BetaRawMessageStopEvent, Anthropic::Models::Beta::BetaRawContentBlockStartEvent, Anthropic::Models::Beta::BetaRawContentBlockDeltaEvent, Anthropic::Models::Beta::BetaRawContentBlockStopEvent>]
|
|
56
|
+
def each_streaming(&blk)
|
|
57
|
+
unless block_given?
|
|
58
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
fold do
|
|
62
|
+
stream = @client.beta.messages.stream(_1)
|
|
63
|
+
blk.call(stream)
|
|
64
|
+
[false, stream.accumulated_message]
|
|
65
|
+
ensure
|
|
66
|
+
stream&.close
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @api private
|
|
71
|
+
#
|
|
72
|
+
# @yieldparam [Array(Boolean, Anthropic::Models::Beta::MessageCreateParams)]
|
|
73
|
+
private def fold(&blk)
|
|
74
|
+
return nil if finished?
|
|
75
|
+
|
|
76
|
+
count =
|
|
77
|
+
case @param
|
|
78
|
+
in {max_iterations: Integer => m}
|
|
79
|
+
m
|
|
80
|
+
else
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# rubocop:disable Metrics/BlockLength
|
|
85
|
+
# rubocop:disable Style/CaseEquality
|
|
86
|
+
loop do
|
|
87
|
+
return if (count = count&.pred)&.negative?
|
|
88
|
+
|
|
89
|
+
tools = params[:tools].to_a.grep(Anthropic::Helpers::Tools::BaseTool)
|
|
90
|
+
messages = current_messages
|
|
91
|
+
brk, response = blk.call(params)
|
|
92
|
+
|
|
93
|
+
next unless current_messages.equal?(messages)
|
|
94
|
+
|
|
95
|
+
mapped =
|
|
96
|
+
response
|
|
97
|
+
.content
|
|
98
|
+
.lazy
|
|
99
|
+
.grep(Anthropic::Beta::BetaToolUseBlock)
|
|
100
|
+
.map do |tool_use|
|
|
101
|
+
resp = {type: :tool_result, tool_use_id: tool_use.id}
|
|
102
|
+
if (tool = tools.find { _1.class.model === tool_use.parsed })
|
|
103
|
+
begin
|
|
104
|
+
raw = tool.call(tool_use.parsed)
|
|
105
|
+
is_error = false
|
|
106
|
+
rescue StandardError => e
|
|
107
|
+
is_error = true
|
|
108
|
+
raw = e.message
|
|
109
|
+
end
|
|
110
|
+
else
|
|
111
|
+
is_error = true
|
|
112
|
+
raw = "Error: parsed '#{tool_use.name}' not found"
|
|
113
|
+
end
|
|
114
|
+
content = raw.is_a?(Array) ? raw : raw.to_s
|
|
115
|
+
{**resp, content:, is_error:}
|
|
116
|
+
end
|
|
117
|
+
.to_a
|
|
118
|
+
|
|
119
|
+
if mapped.empty?
|
|
120
|
+
@finished = true
|
|
121
|
+
break
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
content = response.content.map do
|
|
125
|
+
case _1
|
|
126
|
+
in Anthropic::Beta::BetaToolUseBlock
|
|
127
|
+
raw = {**_1, input: _1.parsed}.except(:parsed)
|
|
128
|
+
Anthropic::Internal::Type::Converter.dump(Anthropic::Beta::BetaToolUseBlock, raw)
|
|
129
|
+
else
|
|
130
|
+
_1
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
messages << {role: :assistant, content:}
|
|
135
|
+
messages << {role: :user, content: mapped}
|
|
136
|
+
|
|
137
|
+
break if brk
|
|
138
|
+
end
|
|
139
|
+
# rubocop:enable Style/CaseEquality
|
|
140
|
+
# rubocop:enable Metrics/BlockLength
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @api private
|
|
144
|
+
#
|
|
145
|
+
# @param client [Anthropic::Client]
|
|
146
|
+
#
|
|
147
|
+
# @param params [Anthropic::Models::Beta::MessageCreateParams]
|
|
148
|
+
def initialize(client, params:)
|
|
149
|
+
@client = client
|
|
150
|
+
@params = params.to_h
|
|
151
|
+
@finished = false
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -201,7 +201,8 @@ module Anthropic
|
|
|
201
201
|
self.class::PLATFORM_HEADERS,
|
|
202
202
|
{
|
|
203
203
|
"accept" => "application/json",
|
|
204
|
-
"content-type" => "application/json"
|
|
204
|
+
"content-type" => "application/json",
|
|
205
|
+
"user-agent" => user_agent
|
|
205
206
|
},
|
|
206
207
|
headers
|
|
207
208
|
)
|
|
@@ -219,6 +220,11 @@ module Anthropic
|
|
|
219
220
|
# @return [Hash{String=>String}]
|
|
220
221
|
private def auth_headers = {}
|
|
221
222
|
|
|
223
|
+
# @api private
|
|
224
|
+
#
|
|
225
|
+
# @return [String]
|
|
226
|
+
private def user_agent = "#{self.class.name}/Ruby #{Anthropic::VERSION}"
|
|
227
|
+
|
|
222
228
|
# @api private
|
|
223
229
|
#
|
|
224
230
|
# @return [String]
|
|
@@ -16,10 +16,11 @@ module Anthropic
|
|
|
16
16
|
class << self
|
|
17
17
|
# @api private
|
|
18
18
|
#
|
|
19
|
+
# @param cert_store [OpenSSL::X509::Store]
|
|
19
20
|
# @param url [URI::Generic]
|
|
20
21
|
#
|
|
21
22
|
# @return [Net::HTTP]
|
|
22
|
-
def connect(url)
|
|
23
|
+
def connect(cert_store:, url:)
|
|
23
24
|
port =
|
|
24
25
|
case [url.port, url.scheme]
|
|
25
26
|
in [Integer, _]
|
|
@@ -33,6 +34,8 @@ module Anthropic
|
|
|
33
34
|
Net::HTTP.new(url.host, port).tap do
|
|
34
35
|
_1.use_ssl = %w[https wss].include?(url.scheme)
|
|
35
36
|
_1.max_retries = 0
|
|
37
|
+
|
|
38
|
+
(_1.cert_store = cert_store) if _1.use_ssl?
|
|
36
39
|
end
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -102,7 +105,7 @@ module Anthropic
|
|
|
102
105
|
pool =
|
|
103
106
|
@mutex.synchronize do
|
|
104
107
|
@pools[origin] ||= ConnectionPool.new(size: @size) do
|
|
105
|
-
self.class.connect(url)
|
|
108
|
+
self.class.connect(cert_store: @cert_store, url: url)
|
|
106
109
|
end
|
|
107
110
|
end
|
|
108
111
|
|
|
@@ -128,40 +131,48 @@ module Anthropic
|
|
|
128
131
|
url, deadline = request.fetch_values(:url, :deadline)
|
|
129
132
|
|
|
130
133
|
req = nil
|
|
131
|
-
eof = false
|
|
132
134
|
finished = false
|
|
133
|
-
closing = nil
|
|
134
135
|
|
|
135
136
|
# rubocop:disable Metrics/BlockLength
|
|
136
137
|
enum = Enumerator.new do |y|
|
|
137
138
|
next if finished
|
|
138
139
|
|
|
139
140
|
with_pool(url, deadline: deadline) do |conn|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
conn.start
|
|
148
|
-
end
|
|
141
|
+
eof = false
|
|
142
|
+
closing = nil
|
|
143
|
+
::Thread.handle_interrupt(Object => :never) do
|
|
144
|
+
::Thread.handle_interrupt(Object => :immediate) do
|
|
145
|
+
req, closing = self.class.build_request(request) do
|
|
146
|
+
self.class.calibrate_socket_timeout(conn, deadline)
|
|
147
|
+
end
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
rsp.read_body do |bytes|
|
|
156
|
-
y << bytes.force_encoding(Encoding::BINARY)
|
|
157
|
-
break if finished
|
|
149
|
+
self.class.calibrate_socket_timeout(conn, deadline)
|
|
150
|
+
unless conn.started?
|
|
151
|
+
conn.keep_alive_timeout = self.class::KEEP_ALIVE_TIMEOUT
|
|
152
|
+
conn.start
|
|
153
|
+
end
|
|
158
154
|
|
|
159
155
|
self.class.calibrate_socket_timeout(conn, deadline)
|
|
156
|
+
conn.request(req) do |rsp|
|
|
157
|
+
y << [req, rsp]
|
|
158
|
+
break if finished
|
|
159
|
+
|
|
160
|
+
rsp.read_body do |bytes|
|
|
161
|
+
y << bytes.force_encoding(Encoding::BINARY)
|
|
162
|
+
break if finished
|
|
163
|
+
|
|
164
|
+
self.class.calibrate_socket_timeout(conn, deadline)
|
|
165
|
+
end
|
|
166
|
+
eof = true
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
ensure
|
|
170
|
+
begin
|
|
171
|
+
conn.finish if !eof && conn&.started?
|
|
172
|
+
ensure
|
|
173
|
+
closing&.call
|
|
160
174
|
end
|
|
161
|
-
eof = true
|
|
162
175
|
end
|
|
163
|
-
ensure
|
|
164
|
-
conn.finish if !eof && conn&.started?
|
|
165
176
|
end
|
|
166
177
|
rescue Timeout::Error
|
|
167
178
|
raise Anthropic::Errors::APITimeoutError.new(url: url, request: req)
|
|
@@ -174,8 +185,6 @@ module Anthropic
|
|
|
174
185
|
body = Anthropic::Internal::Util.fused_enum(enum, external: true) do
|
|
175
186
|
finished = true
|
|
176
187
|
loop { enum.next }
|
|
177
|
-
ensure
|
|
178
|
-
closing&.call
|
|
179
188
|
end
|
|
180
189
|
[Integer(response.code), response, body]
|
|
181
190
|
end
|
|
@@ -186,6 +195,7 @@ module Anthropic
|
|
|
186
195
|
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
|
|
187
196
|
@mutex = Mutex.new
|
|
188
197
|
@size = size
|
|
198
|
+
@cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
|
189
199
|
@pools = {}
|
|
190
200
|
end
|
|
191
201
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Models
|
|
5
|
+
module Beta
|
|
6
|
+
class BetaAllThinkingTurns < Anthropic::Internal::Type::BaseModel
|
|
7
|
+
# @!attribute type
|
|
8
|
+
#
|
|
9
|
+
# @return [Symbol, :all]
|
|
10
|
+
required :type, const: :all
|
|
11
|
+
|
|
12
|
+
# @!method initialize(type: :all)
|
|
13
|
+
# @param type [Symbol, :all]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
BetaAllThinkingTurns = Beta::BetaAllThinkingTurns
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Models
|
|
5
|
+
module Beta
|
|
6
|
+
class BetaClearThinking20251015Edit < Anthropic::Internal::Type::BaseModel
|
|
7
|
+
# @!attribute type
|
|
8
|
+
#
|
|
9
|
+
# @return [Symbol, :clear_thinking_20251015]
|
|
10
|
+
required :type, const: :clear_thinking_20251015
|
|
11
|
+
|
|
12
|
+
# @!attribute keep
|
|
13
|
+
# Number of most recent assistant turns to keep thinking blocks for. Older turns
|
|
14
|
+
# will have their thinking blocks removed.
|
|
15
|
+
#
|
|
16
|
+
# @return [Anthropic::Models::Beta::BetaThinkingTurns, Anthropic::Models::Beta::BetaAllThinkingTurns, Symbol, :all, nil]
|
|
17
|
+
optional :keep, union: -> { Anthropic::Beta::BetaClearThinking20251015Edit::Keep }
|
|
18
|
+
|
|
19
|
+
# @!method initialize(keep: nil, type: :clear_thinking_20251015)
|
|
20
|
+
# Some parameter documentations has been truncated, see
|
|
21
|
+
# {Anthropic::Models::Beta::BetaClearThinking20251015Edit} for more details.
|
|
22
|
+
#
|
|
23
|
+
# @param keep [Anthropic::Models::Beta::BetaThinkingTurns, Anthropic::Models::Beta::BetaAllThinkingTurns, Symbol, :all] Number of most recent assistant turns to keep thinking blocks for. Older turns w
|
|
24
|
+
#
|
|
25
|
+
# @param type [Symbol, :clear_thinking_20251015]
|
|
26
|
+
|
|
27
|
+
# Number of most recent assistant turns to keep thinking blocks for. Older turns
|
|
28
|
+
# will have their thinking blocks removed.
|
|
29
|
+
#
|
|
30
|
+
# @see Anthropic::Models::Beta::BetaClearThinking20251015Edit#keep
|
|
31
|
+
module Keep
|
|
32
|
+
extend Anthropic::Internal::Type::Union
|
|
33
|
+
|
|
34
|
+
variant -> { Anthropic::Beta::BetaThinkingTurns }
|
|
35
|
+
|
|
36
|
+
variant -> { Anthropic::Beta::BetaAllThinkingTurns }
|
|
37
|
+
|
|
38
|
+
variant const: :all
|
|
39
|
+
|
|
40
|
+
# @!method self.variants
|
|
41
|
+
# @return [Array(Anthropic::Models::Beta::BetaThinkingTurns, Anthropic::Models::Beta::BetaAllThinkingTurns, Symbol, :all)]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
BetaClearThinking20251015Edit = Beta::BetaClearThinking20251015Edit
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Models
|
|
5
|
+
module Beta
|
|
6
|
+
class BetaClearThinking20251015EditResponse < Anthropic::Internal::Type::BaseModel
|
|
7
|
+
# @!attribute cleared_input_tokens
|
|
8
|
+
# Number of input tokens cleared by this edit.
|
|
9
|
+
#
|
|
10
|
+
# @return [Integer]
|
|
11
|
+
required :cleared_input_tokens, Integer
|
|
12
|
+
|
|
13
|
+
# @!attribute cleared_thinking_turns
|
|
14
|
+
# Number of thinking turns that were cleared.
|
|
15
|
+
#
|
|
16
|
+
# @return [Integer]
|
|
17
|
+
required :cleared_thinking_turns, Integer
|
|
18
|
+
|
|
19
|
+
# @!attribute type
|
|
20
|
+
# The type of context management edit applied.
|
|
21
|
+
#
|
|
22
|
+
# @return [Symbol, :clear_thinking_20251015]
|
|
23
|
+
required :type, const: :clear_thinking_20251015
|
|
24
|
+
|
|
25
|
+
# @!method initialize(cleared_input_tokens:, cleared_thinking_turns:, type: :clear_thinking_20251015)
|
|
26
|
+
# @param cleared_input_tokens [Integer] Number of input tokens cleared by this edit.
|
|
27
|
+
#
|
|
28
|
+
# @param cleared_thinking_turns [Integer] Number of thinking turns that were cleared.
|
|
29
|
+
#
|
|
30
|
+
# @param type [Symbol, :clear_thinking_20251015] The type of context management edit applied.
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
BetaClearThinking20251015EditResponse = Beta::BetaClearThinking20251015EditResponse
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -7,11 +7,25 @@ module Anthropic
|
|
|
7
7
|
# @!attribute edits
|
|
8
8
|
# List of context management edits to apply
|
|
9
9
|
#
|
|
10
|
-
# @return [Array<Anthropic::Models::Beta::BetaClearToolUses20250919Edit>, nil]
|
|
11
|
-
optional :edits,
|
|
10
|
+
# @return [Array<Anthropic::Models::Beta::BetaClearToolUses20250919Edit, Anthropic::Models::Beta::BetaClearThinking20251015Edit>, nil]
|
|
11
|
+
optional :edits,
|
|
12
|
+
-> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaContextManagementConfig::Edit] }
|
|
12
13
|
|
|
13
14
|
# @!method initialize(edits: nil)
|
|
14
|
-
# @param edits [Array<Anthropic::Models::Beta::BetaClearToolUses20250919Edit>] List of context management edits to apply
|
|
15
|
+
# @param edits [Array<Anthropic::Models::Beta::BetaClearToolUses20250919Edit, Anthropic::Models::Beta::BetaClearThinking20251015Edit>] List of context management edits to apply
|
|
16
|
+
|
|
17
|
+
module Edit
|
|
18
|
+
extend Anthropic::Internal::Type::Union
|
|
19
|
+
|
|
20
|
+
discriminator :type
|
|
21
|
+
|
|
22
|
+
variant :clear_tool_uses_20250919, -> { Anthropic::Beta::BetaClearToolUses20250919Edit }
|
|
23
|
+
|
|
24
|
+
variant :clear_thinking_20251015, -> { Anthropic::Beta::BetaClearThinking20251015Edit }
|
|
25
|
+
|
|
26
|
+
# @!method self.variants
|
|
27
|
+
# @return [Array(Anthropic::Models::Beta::BetaClearToolUses20250919Edit, Anthropic::Models::Beta::BetaClearThinking20251015Edit)]
|
|
28
|
+
end
|
|
15
29
|
end
|
|
16
30
|
end
|
|
17
31
|
|
|
@@ -7,12 +7,25 @@ module Anthropic
|
|
|
7
7
|
# @!attribute applied_edits
|
|
8
8
|
# List of context management edits that were applied.
|
|
9
9
|
#
|
|
10
|
-
# @return [Array<Anthropic::Models::Beta::BetaClearToolUses20250919EditResponse>]
|
|
10
|
+
# @return [Array<Anthropic::Models::Beta::BetaClearToolUses20250919EditResponse, Anthropic::Models::Beta::BetaClearThinking20251015EditResponse>]
|
|
11
11
|
required :applied_edits,
|
|
12
|
-
-> { Anthropic::Internal::Type::ArrayOf[Anthropic::Beta::
|
|
12
|
+
-> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::Beta::BetaContextManagementResponse::AppliedEdit] }
|
|
13
13
|
|
|
14
14
|
# @!method initialize(applied_edits:)
|
|
15
|
-
# @param applied_edits [Array<Anthropic::Models::Beta::BetaClearToolUses20250919EditResponse>] List of context management edits that were applied.
|
|
15
|
+
# @param applied_edits [Array<Anthropic::Models::Beta::BetaClearToolUses20250919EditResponse, Anthropic::Models::Beta::BetaClearThinking20251015EditResponse>] List of context management edits that were applied.
|
|
16
|
+
|
|
17
|
+
module AppliedEdit
|
|
18
|
+
extend Anthropic::Internal::Type::Union
|
|
19
|
+
|
|
20
|
+
discriminator :type
|
|
21
|
+
|
|
22
|
+
variant :clear_tool_uses_20250919, -> { Anthropic::Beta::BetaClearToolUses20250919EditResponse }
|
|
23
|
+
|
|
24
|
+
variant :clear_thinking_20251015, -> { Anthropic::Beta::BetaClearThinking20251015EditResponse }
|
|
25
|
+
|
|
26
|
+
# @!method self.variants
|
|
27
|
+
# @return [Array(Anthropic::Models::Beta::BetaClearToolUses20250919EditResponse, Anthropic::Models::Beta::BetaClearThinking20251015EditResponse)]
|
|
28
|
+
end
|
|
16
29
|
end
|
|
17
30
|
end
|
|
18
31
|
|
|
@@ -11,8 +11,8 @@ module Anthropic
|
|
|
11
11
|
|
|
12
12
|
# @!attribute input
|
|
13
13
|
#
|
|
14
|
-
# @return [Object]
|
|
15
|
-
required :input, Anthropic::Internal::Type::Unknown
|
|
14
|
+
# @return [Hash{Symbol=>Object}]
|
|
15
|
+
required :input, Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown]
|
|
16
16
|
|
|
17
17
|
# @!attribute name
|
|
18
18
|
#
|
|
@@ -39,7 +39,7 @@ module Anthropic
|
|
|
39
39
|
# @!method initialize(id:, input:, name:, server_name:, cache_control: nil, type: :mcp_tool_use)
|
|
40
40
|
# @param id [String]
|
|
41
41
|
#
|
|
42
|
-
# @param input [Object]
|
|
42
|
+
# @param input [Hash{Symbol=>Object}]
|
|
43
43
|
#
|
|
44
44
|
# @param name [String]
|
|
45
45
|
#
|
|
@@ -11,8 +11,8 @@ module Anthropic
|
|
|
11
11
|
|
|
12
12
|
# @!attribute input
|
|
13
13
|
#
|
|
14
|
-
# @return [Object]
|
|
15
|
-
required :input, Anthropic::Internal::Type::Unknown
|
|
14
|
+
# @return [Hash{Symbol=>Object}]
|
|
15
|
+
required :input, Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown]
|
|
16
16
|
|
|
17
17
|
# @!attribute name
|
|
18
18
|
#
|
|
@@ -33,7 +33,7 @@ module Anthropic
|
|
|
33
33
|
# @!method initialize(id:, input:, name:, cache_control: nil, type: :server_tool_use)
|
|
34
34
|
# @param id [String]
|
|
35
35
|
#
|
|
36
|
-
# @param input [Object]
|
|
36
|
+
# @param input [Hash{Symbol=>Object}]
|
|
37
37
|
#
|
|
38
38
|
# @param name [Symbol, Anthropic::Models::Beta::BetaServerToolUseBlockParam::Name]
|
|
39
39
|
#
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Models
|
|
5
|
+
module Beta
|
|
6
|
+
class BetaThinkingTurns < Anthropic::Internal::Type::BaseModel
|
|
7
|
+
# @!attribute type
|
|
8
|
+
#
|
|
9
|
+
# @return [Symbol, :thinking_turns]
|
|
10
|
+
required :type, const: :thinking_turns
|
|
11
|
+
|
|
12
|
+
# @!attribute value
|
|
13
|
+
#
|
|
14
|
+
# @return [Integer]
|
|
15
|
+
required :value, Integer
|
|
16
|
+
|
|
17
|
+
# @!method initialize(value:, type: :thinking_turns)
|
|
18
|
+
# @param value [Integer]
|
|
19
|
+
# @param type [Symbol, :thinking_turns]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
BetaThinkingTurns = Beta::BetaThinkingTurns
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -66,8 +66,10 @@ module Anthropic
|
|
|
66
66
|
|
|
67
67
|
# @!attribute properties
|
|
68
68
|
#
|
|
69
|
-
# @return [Object, nil]
|
|
70
|
-
optional :properties,
|
|
69
|
+
# @return [Hash{Symbol=>Object}, nil]
|
|
70
|
+
optional :properties,
|
|
71
|
+
Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown],
|
|
72
|
+
nil?: true
|
|
71
73
|
|
|
72
74
|
# @!attribute required
|
|
73
75
|
#
|
|
@@ -80,7 +82,7 @@ module Anthropic
|
|
|
80
82
|
# This defines the shape of the `input` that your tool accepts and that the model
|
|
81
83
|
# will produce.
|
|
82
84
|
#
|
|
83
|
-
# @param properties [Object, nil]
|
|
85
|
+
# @param properties [Hash{Symbol=>Object}, nil]
|
|
84
86
|
# @param required [Array<String>, nil]
|
|
85
87
|
# @param type [Symbol, :object]
|
|
86
88
|
end
|
|
@@ -24,6 +24,20 @@ module Anthropic
|
|
|
24
24
|
# @return [Symbol, :tool_use]
|
|
25
25
|
required :type, const: :tool_use
|
|
26
26
|
|
|
27
|
+
response_only do
|
|
28
|
+
# @api public
|
|
29
|
+
#
|
|
30
|
+
# Parsed input data coerced to the tool's input schema model.
|
|
31
|
+
# Only present when tools are defined using the InputSchema DSL.
|
|
32
|
+
required :parsed, Anthropic::Internal::Type::Unknown
|
|
33
|
+
|
|
34
|
+
# @api private
|
|
35
|
+
#
|
|
36
|
+
# Internal buffer for accumulating partial JSON during streaming.
|
|
37
|
+
# Used by streaming helpers to reconstruct complete JSON input from deltas.
|
|
38
|
+
optional :_json_buf, String
|
|
39
|
+
end
|
|
40
|
+
|
|
27
41
|
# @!method initialize(id:, input:, name:, type: :tool_use)
|
|
28
42
|
# @param id [String]
|
|
29
43
|
# @param input [Object]
|
|
@@ -11,8 +11,8 @@ module Anthropic
|
|
|
11
11
|
|
|
12
12
|
# @!attribute input
|
|
13
13
|
#
|
|
14
|
-
# @return [Object]
|
|
15
|
-
required :input, Anthropic::Internal::Type::Unknown
|
|
14
|
+
# @return [Hash{Symbol=>Object}]
|
|
15
|
+
required :input, Anthropic::Internal::Type::HashOf[Anthropic::Internal::Type::Unknown]
|
|
16
16
|
|
|
17
17
|
# @!attribute name
|
|
18
18
|
#
|
|
@@ -33,7 +33,7 @@ module Anthropic
|
|
|
33
33
|
# @!method initialize(id:, input:, name:, cache_control: nil, type: :tool_use)
|
|
34
34
|
# @param id [String]
|
|
35
35
|
#
|
|
36
|
-
# @param input [Object]
|
|
36
|
+
# @param input [Hash{Symbol=>Object}]
|
|
37
37
|
#
|
|
38
38
|
# @param name [String]
|
|
39
39
|
#
|