riffer 0.55.0 → 0.56.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +18 -0
- data/README.md +2 -1
- data/UPGRADING.md +3 -0
- data/docs/AGENT_LIFECYCLE.md +1 -1
- data/docs/CONFIGURATION.md +48 -1
- data/docs/GUARDRAILS.md +2 -0
- data/docs/MESSAGES.md +112 -15
- data/docs/STABILITY.md +32 -0
- data/docs/STREAM_EVENTS.md +16 -0
- data/docs/TESTING.md +22 -1
- data/docs/providers/AMAZON_BEDROCK.md +1 -1
- data/docs/providers/ANTHROPIC.md +18 -14
- data/docs/providers/CUSTOM_PROVIDERS.md +24 -0
- data/docs/providers/GEMINI.md +1 -1
- data/docs/providers/GOOGLE_CLOUD.md +1 -1
- data/docs/providers/MOCK_PROVIDER.md +2 -0
- data/docs/providers/OPENAI.md +3 -1
- data/docs-site/manifest.yml +3 -0
- data/lib/riffer/agent/run.rb +28 -13
- data/lib/riffer/agent/session.rb +33 -10
- data/lib/riffer/config/future.rb +53 -0
- data/lib/riffer/config/pricing.rb +5 -15
- data/lib/riffer/config.rb +16 -0
- data/lib/riffer/deprecation/event.rb +25 -0
- data/lib/riffer/deprecation.rb +60 -0
- data/lib/riffer/messages/assistant/server_tool_part.rb +73 -0
- data/lib/riffer/messages/assistant/text_part.rb +52 -0
- data/lib/riffer/messages/assistant.rb +64 -17
- data/lib/riffer/providers/anthropic_compatible/messages_api/stream.rb +25 -1
- data/lib/riffer/providers/anthropic_compatible/messages_api.rb +51 -29
- data/lib/riffer/providers/base.rb +15 -6
- data/lib/riffer/providers/open_ai.rb +21 -16
- data/lib/riffer/stream_events/server_tool_done.rb +21 -0
- data/lib/riffer/testing.rb +6 -0
- data/lib/riffer/version.rb +1 -1
- data/lib/riffer.rb +2 -0
- data/sig/generated/riffer/agent/run.rbs +5 -0
- data/sig/generated/riffer/agent/session.rbs +6 -0
- data/sig/generated/riffer/config/future.rbs +29 -0
- data/sig/generated/riffer/config/pricing.rbs +0 -9
- data/sig/generated/riffer/config.rbs +8 -0
- data/sig/generated/riffer/deprecation/event.rbs +17 -0
- data/sig/generated/riffer/deprecation.rbs +27 -0
- data/sig/generated/riffer/messages/assistant/server_tool_part.rbs +44 -0
- data/sig/generated/riffer/messages/assistant/text_part.rbs +35 -0
- data/sig/generated/riffer/messages/assistant.rbs +24 -11
- data/sig/generated/riffer/providers/anthropic_compatible/messages_api/stream.rbs +10 -0
- data/sig/generated/riffer/providers/anthropic_compatible/messages_api.rbs +18 -9
- data/sig/generated/riffer/providers/base.rbs +5 -0
- data/sig/generated/riffer/providers/open_ai.rbs +7 -2
- data/sig/generated/riffer/stream_events/server_tool_done.rbs +15 -0
- data/sig/generated/riffer/testing.rbs +4 -0
- data/sig/generated/riffer.rbs +3 -0
- data/sig/manual/riffer/deprecation.rbs +5 -0
- metadata +16 -1
|
@@ -18,7 +18,7 @@ class Riffer::Providers::AnthropicCompatible::MessagesAPI < Riffer::Providers::B
|
|
|
18
18
|
|
|
19
19
|
# Only parts carrying this tag are replayed, so reasoning captured by another
|
|
20
20
|
# adapter, whose signatures the Messages API may not accept, never reaches the
|
|
21
|
-
# request.
|
|
21
|
+
# request. Server tool parts and text parts that keep their block carry it too.
|
|
22
22
|
REASONING_FORMAT = "anthropic-messages-v1" #: String
|
|
23
23
|
|
|
24
24
|
#--
|
|
@@ -72,30 +72,35 @@ class Riffer::Providers::AnthropicCompatible::MessagesAPI < Riffer::Providers::B
|
|
|
72
72
|
yielder << Riffer::StreamEvents::TokenUsageDone.new(token_usage: usage) if usage
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# Claude signs each thinking block over every block before it in the turn, so
|
|
76
|
+
# the blocks go back in the order they came.
|
|
75
77
|
#--
|
|
76
|
-
#: (Hash[Symbol, untyped]) ->
|
|
77
|
-
def
|
|
78
|
-
content_blocks(response).filter_map { |block| block[:text] if block[:type] == "text" }.join
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
#--
|
|
82
|
-
#: (Hash[Symbol, untyped]) -> Array[Riffer::Messages::Assistant::ToolCall]
|
|
83
|
-
def extract_tool_calls(response)
|
|
78
|
+
#: (Hash[Symbol, untyped]) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
79
|
+
def extract_parts(response)
|
|
84
80
|
content_blocks(response).filter_map do |block|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
case block[:type]
|
|
82
|
+
when "text" then text_part(block)
|
|
83
|
+
when "tool_use"
|
|
84
|
+
Riffer::Messages::Assistant::ToolCall.new(
|
|
85
|
+
call_id: block[:id],
|
|
86
|
+
name: decode_tool_name(block[:name], tools: @current_tools),
|
|
87
|
+
arguments: (block[:input] || {}).to_json,
|
|
88
|
+
)
|
|
89
|
+
when "server_tool_use", Stream::SERVER_TOOL_RESULT_TYPE then Stream.server_tool_part(block)
|
|
90
|
+
else Stream.reasoning_part(block)
|
|
91
|
+
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
# The block is kept only when it carries citations, which point into the
|
|
96
|
+
# search results and go back with the text.
|
|
95
97
|
#--
|
|
96
|
-
#: (Hash[Symbol, untyped]) ->
|
|
97
|
-
def
|
|
98
|
-
|
|
98
|
+
#: (Hash[Symbol, untyped]) -> Riffer::Messages::Assistant::TextPart
|
|
99
|
+
def text_part(block)
|
|
100
|
+
citations = block[:citations]
|
|
101
|
+
return Riffer::Messages::Assistant::TextPart.new(block[:text].to_s) if citations.nil? || citations.empty?
|
|
102
|
+
|
|
103
|
+
Riffer::Messages::Assistant::TextPart.new(block[:text].to_s, data: JSON.generate(block), format: REASONING_FORMAT)
|
|
99
104
|
end
|
|
100
105
|
|
|
101
106
|
#--
|
|
@@ -242,21 +247,38 @@ class Riffer::Providers::AnthropicCompatible::MessagesAPI < Riffer::Providers::B
|
|
|
242
247
|
#--
|
|
243
248
|
#: (Riffer::Messages::Assistant) -> Hash[Symbol, untyped]
|
|
244
249
|
def convert_assistant(message)
|
|
245
|
-
content
|
|
246
|
-
|
|
247
|
-
end
|
|
248
|
-
content << { type: "text", text: message.content } if message.content && !message.content.empty?
|
|
250
|
+
{ role: "assistant", content: message.parts.filter_map { |part| convert_part(part) } }
|
|
251
|
+
end
|
|
249
252
|
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
#--
|
|
254
|
+
#: (Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart) -> Hash[Symbol, untyped]?
|
|
255
|
+
def convert_part(part)
|
|
256
|
+
case part
|
|
257
|
+
when Riffer::Messages::Assistant::TextPart then convert_text_part(part)
|
|
258
|
+
when Riffer::Messages::Assistant::ToolCall
|
|
259
|
+
{
|
|
252
260
|
type: "tool_use",
|
|
253
|
-
id:
|
|
254
|
-
name: encode_tool_name(
|
|
255
|
-
input: parse_tool_arguments(
|
|
261
|
+
id: part.call_id,
|
|
262
|
+
name: encode_tool_name(part.name),
|
|
263
|
+
input: parse_tool_arguments(part.arguments),
|
|
256
264
|
}
|
|
265
|
+
when Riffer::Messages::Assistant::ServerToolPart
|
|
266
|
+
JSON.parse(part.data, symbolize_names: true) if part.format == REASONING_FORMAT
|
|
267
|
+
when Riffer::Messages::Assistant::ReasoningPart
|
|
268
|
+
convert_reasoning_part(part) if part.format == REASONING_FORMAT
|
|
257
269
|
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# The API rejects text blocks that are empty or only whitespace.
|
|
273
|
+
#--
|
|
274
|
+
#: (Riffer::Messages::Assistant::TextPart) -> Hash[Symbol, untyped]?
|
|
275
|
+
def convert_text_part(part)
|
|
276
|
+
return nil if part.text.strip.empty?
|
|
277
|
+
|
|
278
|
+
data = part.data
|
|
279
|
+
return JSON.parse(data, symbolize_names: true) if data && part.format == REASONING_FORMAT
|
|
258
280
|
|
|
259
|
-
{
|
|
281
|
+
{ type: "text", text: part.text }
|
|
260
282
|
end
|
|
261
283
|
|
|
262
284
|
#--
|
|
@@ -45,9 +45,9 @@ class Riffer::Providers::Base
|
|
|
45
45
|
in_chat_span(model, messages, options) do |span|
|
|
46
46
|
response = execute_generate(params)
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
parts = extract_parts(response)
|
|
49
|
+
content = parts.filter_map { |part| part.text if part.is_a?(Riffer::Messages::Assistant::TextPart) }.join
|
|
50
|
+
tool_calls = parts.grep(Riffer::Messages::Assistant::ToolCall) #: Array[Riffer::Messages::Assistant::ToolCall]
|
|
51
51
|
token_usage = extract_token_usage(response)
|
|
52
52
|
finish_reason = extract_finish_reason(response)
|
|
53
53
|
structured_output = parse_structured_output(content) if options[:structured_output] && tool_calls.empty?
|
|
@@ -57,9 +57,7 @@ class Riffer::Providers::Base
|
|
|
57
57
|
capture_output(span, content: content, tool_calls: tool_calls, finish_reason: finish_reason&.reason)
|
|
58
58
|
|
|
59
59
|
Riffer::Messages::Assistant.new(
|
|
60
|
-
|
|
61
|
-
tool_calls: tool_calls,
|
|
62
|
-
reasoning: reasoning,
|
|
60
|
+
parts: parts,
|
|
63
61
|
token_usage: token_usage,
|
|
64
62
|
structured_output: structured_output,
|
|
65
63
|
finish_reason: finish_reason&.reason,
|
|
@@ -256,6 +254,17 @@ class Riffer::Providers::Base
|
|
|
256
254
|
nil
|
|
257
255
|
end
|
|
258
256
|
|
|
257
|
+
# Override when the provider interleaves blocks in one turn and needs them back in that order.
|
|
258
|
+
#--
|
|
259
|
+
#: (untyped) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
260
|
+
def extract_parts(response)
|
|
261
|
+
Riffer::Messages::Assistant.new(
|
|
262
|
+
extract_content(response),
|
|
263
|
+
tool_calls: extract_tool_calls(response),
|
|
264
|
+
reasoning: extract_reasoning(response),
|
|
265
|
+
).parts
|
|
266
|
+
end
|
|
267
|
+
|
|
259
268
|
#--
|
|
260
269
|
#: (untyped) -> Array[Riffer::Messages::Assistant::ReasoningPart]
|
|
261
270
|
def extract_reasoning(_response)
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
5
5
|
WEB_SEARCH_TOOL_TYPE = "web_search_preview" #: String
|
|
6
6
|
|
|
7
|
+
# Without this include, a web_search_call's search action carries no sources.
|
|
8
|
+
WEB_SEARCH_SOURCES_INCLUDE = "web_search_call.action.sources" #: String
|
|
9
|
+
|
|
7
10
|
# The Responses API has no finish_reason field, and an +incomplete+ status is only meaningful
|
|
8
11
|
# together with <tt>incomplete_details.reason</tt>.
|
|
9
12
|
FINISH_REASONS = {
|
|
@@ -94,6 +97,7 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
94
97
|
web_search_tool = { type: WEB_SEARCH_TOOL_TYPE }
|
|
95
98
|
web_search_tool.merge!(web_search) if web_search.is_a?(Hash)
|
|
96
99
|
openai_tools << web_search_tool
|
|
100
|
+
params[:include] = [*params[:include], WEB_SEARCH_SOURCES_INCLUDE].uniq(&:to_s)
|
|
97
101
|
end
|
|
98
102
|
|
|
99
103
|
if structured_output
|
|
@@ -195,6 +199,8 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
195
199
|
|
|
196
200
|
typed_response.output.each do |item|
|
|
197
201
|
next unless item.is_a?(::OpenAI::Models::Responses::ResponseFunctionToolCall)
|
|
202
|
+
# A call cut off by max_output_tokens has truncated arguments that can't be run.
|
|
203
|
+
next if item.status == :incomplete
|
|
198
204
|
|
|
199
205
|
tool_calls << Riffer::Messages::Assistant::ToolCall.new(
|
|
200
206
|
call_id: item.call_id,
|
|
@@ -247,7 +253,7 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
247
253
|
def execute_stream(params, yielder)
|
|
248
254
|
current_state = {
|
|
249
255
|
text: nil,
|
|
250
|
-
|
|
256
|
+
tool_names: {},
|
|
251
257
|
} #: Hash[Symbol, untyped]
|
|
252
258
|
|
|
253
259
|
stream_completed = false
|
|
@@ -266,8 +272,6 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
266
272
|
handle_reasoning_summary_text_delta(event, state: current_state, yielder: yielder)
|
|
267
273
|
when :"response.function_call_arguments.delta"
|
|
268
274
|
handle_function_call_arguments_delta(event, state: current_state, yielder: yielder)
|
|
269
|
-
when :"response.function_call_arguments.done"
|
|
270
|
-
handle_function_call_arguments_done(event, state: current_state, yielder: yielder)
|
|
271
275
|
when :"response.web_search_call.in_progress"
|
|
272
276
|
handle_web_search_status(event, status: "in_progress", yielder: yielder)
|
|
273
277
|
when :"response.web_search_call.searching"
|
|
@@ -276,6 +280,7 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
276
280
|
handle_web_search_status(event, status: "completed", yielder: yielder)
|
|
277
281
|
when :"response.output_item.done"
|
|
278
282
|
case event.item&.type
|
|
283
|
+
when :function_call then handle_output_item_done_function_call(event, yielder: yielder)
|
|
279
284
|
when :web_search_call then handle_output_item_done_web_search(event, yielder: yielder)
|
|
280
285
|
when :reasoning then handle_output_item_done_reasoning(event, yielder: yielder)
|
|
281
286
|
end
|
|
@@ -299,10 +304,7 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
299
304
|
#--
|
|
300
305
|
#: (untyped, state: Hash[Symbol, untyped], yielder: Riffer::Providers::_EventSink) -> void
|
|
301
306
|
def handle_output_item_added_function_call(event, state:, yielder:)
|
|
302
|
-
state[:
|
|
303
|
-
name: decode_tool_name(event.item.name, tools: @current_tools),
|
|
304
|
-
call_id: event.item.call_id,
|
|
305
|
-
}
|
|
307
|
+
state[:tool_names][event.item.id] = decode_tool_name(event.item.name, tools: @current_tools)
|
|
306
308
|
end
|
|
307
309
|
|
|
308
310
|
#--
|
|
@@ -324,23 +326,26 @@ class Riffer::Providers::OpenAI < Riffer::Providers::Base
|
|
|
324
326
|
#--
|
|
325
327
|
#: (untyped, state: Hash[Symbol, untyped], yielder: Riffer::Providers::_EventSink) -> void
|
|
326
328
|
def handle_function_call_arguments_delta(event, state:, yielder:)
|
|
327
|
-
tracked = state[:tool_info][event.item_id] || {}
|
|
328
329
|
yielder << Riffer::StreamEvents::ToolCallDelta.new(
|
|
329
330
|
item_id: event.item_id,
|
|
330
|
-
name:
|
|
331
|
+
name: state[:tool_names][event.item_id],
|
|
331
332
|
arguments_delta: event.delta,
|
|
332
333
|
)
|
|
333
334
|
end
|
|
334
335
|
|
|
336
|
+
# Emitted from the finished item rather than function_call_arguments.done, because only the
|
|
337
|
+
# item's status marks a call cut off by max_output_tokens, whose arguments can't be run.
|
|
335
338
|
#--
|
|
336
|
-
#: (untyped,
|
|
337
|
-
def
|
|
338
|
-
|
|
339
|
+
#: (untyped, yielder: Riffer::Providers::_EventSink) -> void
|
|
340
|
+
def handle_output_item_done_function_call(event, yielder:)
|
|
341
|
+
item = event.item
|
|
342
|
+
return if item.status == :incomplete
|
|
343
|
+
|
|
339
344
|
yielder << Riffer::StreamEvents::ToolCallDone.new(
|
|
340
|
-
item_id:
|
|
341
|
-
call_id:
|
|
342
|
-
name:
|
|
343
|
-
arguments:
|
|
345
|
+
item_id: item.id,
|
|
346
|
+
call_id: item.call_id,
|
|
347
|
+
name: decode_tool_name(item.name, tools: @current_tools),
|
|
348
|
+
arguments: item.arguments,
|
|
344
349
|
)
|
|
345
350
|
end
|
|
346
351
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Carries a server tool block for replay. WebSearchStatus and WebSearchDone are the events to
|
|
5
|
+
# display.
|
|
6
|
+
class Riffer::StreamEvents::ServerToolDone < Riffer::StreamEvents::Base
|
|
7
|
+
attr_reader :part #: Riffer::Messages::Assistant::ServerToolPart # @dynamic part
|
|
8
|
+
|
|
9
|
+
#--
|
|
10
|
+
#: (Riffer::Messages::Assistant::ServerToolPart, ?role: Symbol) -> void
|
|
11
|
+
def initialize(part, role: :assistant)
|
|
12
|
+
super(role: role)
|
|
13
|
+
@part = part
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
#--
|
|
17
|
+
#: () -> Hash[Symbol, untyped]
|
|
18
|
+
def to_h
|
|
19
|
+
{ role: @role, part: part.to_h }
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/riffer/testing.rb
CHANGED
data/lib/riffer/version.rb
CHANGED
data/lib/riffer.rb
CHANGED
|
@@ -23,6 +23,11 @@ module Riffer::Agent::Run
|
|
|
23
23
|
# : (Riffer::Agent, Enumerator::Yielder, ?Hash[String, String]) -> Riffer::Messages::Assistant
|
|
24
24
|
def accumulate_streamed_response: (Riffer::Agent, Enumerator::Yielder, ?Hash[String, String]) -> Riffer::Messages::Assistant
|
|
25
25
|
|
|
26
|
+
# TextDone is the adapter's authoritative full text, so it wins over the deltas.
|
|
27
|
+
# --
|
|
28
|
+
# : (Array[String | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart], String?) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
29
|
+
def streamed_parts: (Array[String | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart], String?) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
30
|
+
|
|
26
31
|
# --
|
|
27
32
|
# : (Enumerator::Yielder?, Array[Riffer::Guardrails::Modification], Array[Riffer::Guardrails::Modification]) -> void
|
|
28
33
|
def record_modifications!: (Enumerator::Yielder?, Array[Riffer::Guardrails::Modification], Array[Riffer::Guardrails::Modification]) -> void
|
|
@@ -80,4 +80,10 @@ class Riffer::Agent::Session
|
|
|
80
80
|
# --
|
|
81
81
|
# : (Riffer::Messages::Base, Hash[Symbol, untyped]) -> Riffer::Messages::Base
|
|
82
82
|
def rebuild_message: (Riffer::Messages::Base, Hash[Symbol, untyped]) -> Riffer::Messages::Base
|
|
83
|
+
|
|
84
|
+
# A +content+, +tool_calls+ or +reasoning+ edit rebuilds the parts in the default order, which
|
|
85
|
+
# drops server tool parts; +parts:+ replaces them as given.
|
|
86
|
+
# --
|
|
87
|
+
# : (Riffer::Messages::Assistant, Hash[Symbol, untyped]) -> Riffer::Messages::Assistant
|
|
88
|
+
def rebuild_assistant: (Riffer::Messages::Assistant, Hash[Symbol, untyped]) -> Riffer::Messages::Assistant
|
|
83
89
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Generated from lib/riffer/config/future.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Riffer::Config::Future
|
|
4
|
+
# Steep can't type an empty literal; drop the ignore once FLAGS has an entry.
|
|
5
|
+
# steep:ignore:start
|
|
6
|
+
FLAGS: Hash[Symbol, { default: bool }]
|
|
7
|
+
|
|
8
|
+
@flags: Hash[Symbol, { default: bool }]
|
|
9
|
+
|
|
10
|
+
@enabled: Hash[Symbol, bool]
|
|
11
|
+
|
|
12
|
+
# --
|
|
13
|
+
# : (?flags: Hash[Symbol, { default: bool }]) -> void
|
|
14
|
+
def initialize: (?flags: Hash[Symbol, { default: bool }]) -> void
|
|
15
|
+
|
|
16
|
+
# --
|
|
17
|
+
# : (Symbol) -> bool
|
|
18
|
+
def enabled?: (Symbol) -> bool
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
# --
|
|
23
|
+
# : (Symbol, untyped) -> void
|
|
24
|
+
def set: (Symbol, untyped) -> void
|
|
25
|
+
|
|
26
|
+
# --
|
|
27
|
+
# : (Symbol) -> { default: bool }
|
|
28
|
+
def flag: (Symbol) -> { default: bool }
|
|
29
|
+
end
|
|
@@ -3,12 +3,8 @@
|
|
|
3
3
|
# @deprecated Set pricing in a catalog file instead (see docs/CATALOG.md).
|
|
4
4
|
# A catalog entry's pricing wins over rates registered here.
|
|
5
5
|
class Riffer::Config::Pricing
|
|
6
|
-
DEPRECATION_MESSAGE: String
|
|
7
|
-
|
|
8
6
|
@rates: Hash[String, Riffer::Catalog::Rates]
|
|
9
7
|
|
|
10
|
-
self.@warned: bool
|
|
11
|
-
|
|
12
8
|
# --
|
|
13
9
|
# : () -> void
|
|
14
10
|
def initialize: () -> void
|
|
@@ -24,9 +20,4 @@ class Riffer::Config::Pricing
|
|
|
24
20
|
# --
|
|
25
21
|
# : () -> bool
|
|
26
22
|
def empty?: () -> bool
|
|
27
|
-
|
|
28
|
-
# Once per process, so a boot that sets many models logs one line.
|
|
29
|
-
# --
|
|
30
|
-
# : () -> void
|
|
31
|
-
def self.warn_deprecated: () -> void
|
|
32
23
|
end
|
|
@@ -35,6 +35,8 @@ class Riffer::Config
|
|
|
35
35
|
|
|
36
36
|
attr_reader files: Riffer::Config::Files
|
|
37
37
|
|
|
38
|
+
attr_reader future: Riffer::Config::Future
|
|
39
|
+
|
|
38
40
|
# @deprecated Use +catalog_files+.
|
|
39
41
|
attr_reader pricing: Riffer::Config::Pricing
|
|
40
42
|
|
|
@@ -60,6 +62,12 @@ class Riffer::Config
|
|
|
60
62
|
# : (Symbol) -> void
|
|
61
63
|
def message_id_strategy=: (Symbol) -> void
|
|
62
64
|
|
|
65
|
+
attr_reader deprecations: Symbol | ^(Riffer::Deprecation::Event) -> void
|
|
66
|
+
|
|
67
|
+
# --
|
|
68
|
+
# : ((Symbol | ^(Riffer::Deprecation::Event) -> void)) -> void
|
|
69
|
+
def deprecations=: (Symbol | ^(Riffer::Deprecation::Event) -> void) -> void
|
|
70
|
+
|
|
63
71
|
# --
|
|
64
72
|
# : () -> void
|
|
65
73
|
def initialize: () -> void
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Generated from lib/riffer/deprecation/event.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Riffer::Deprecation::Event
|
|
4
|
+
attr_reader id: Symbol
|
|
5
|
+
|
|
6
|
+
attr_reader message: String
|
|
7
|
+
|
|
8
|
+
attr_reader location: String?
|
|
9
|
+
|
|
10
|
+
# --
|
|
11
|
+
# : (id: Symbol, message: String, location: String?) -> void
|
|
12
|
+
def initialize: (id: Symbol, message: String, location: String?) -> void
|
|
13
|
+
|
|
14
|
+
# --
|
|
15
|
+
# : () -> String
|
|
16
|
+
def to_s: () -> String
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Generated from lib/riffer/deprecation.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Riffer::Deprecation
|
|
4
|
+
@mutex: Thread::Mutex
|
|
5
|
+
|
|
6
|
+
@reported: Set[[ Symbol, String? ]]
|
|
7
|
+
|
|
8
|
+
MODES: Array[Symbol]
|
|
9
|
+
|
|
10
|
+
LIB_DIR: String
|
|
11
|
+
|
|
12
|
+
ALLOWED_KEY: Symbol
|
|
13
|
+
|
|
14
|
+
# --
|
|
15
|
+
# : (id: Symbol, message: String) -> void
|
|
16
|
+
def warn: (id: Symbol, message: String) -> void
|
|
17
|
+
|
|
18
|
+
# --
|
|
19
|
+
# : [T] () { () -> T } -> T
|
|
20
|
+
def allow: [T] () { () -> T } -> T
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# --
|
|
25
|
+
# : (Event) -> bool
|
|
26
|
+
def first_report?: (Event) -> bool
|
|
27
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Generated from lib/riffer/messages/assistant/server_tool_part.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
# A call or result of a tool the provider ran itself (e.g. web search). Stored and replayed
|
|
4
|
+
# verbatim under the same rule as reasoning parts: only the adapter whose +format+ it is sends
|
|
5
|
+
# it back.
|
|
6
|
+
class Riffer::Messages::Assistant::ServerToolPart
|
|
7
|
+
KINDS: Array[Symbol]
|
|
8
|
+
|
|
9
|
+
attr_reader name: String
|
|
10
|
+
|
|
11
|
+
attr_reader kind: Symbol
|
|
12
|
+
|
|
13
|
+
# The provider's block, JSON-encoded and unchanged.
|
|
14
|
+
attr_reader data: String
|
|
15
|
+
|
|
16
|
+
# Shared by a call and its result.
|
|
17
|
+
attr_reader id: String?
|
|
18
|
+
|
|
19
|
+
attr_reader format: String?
|
|
20
|
+
|
|
21
|
+
# --
|
|
22
|
+
# : ((Hash[Symbol, untyped] | Riffer::Messages::Assistant::ServerToolPart)) -> Riffer::Messages::Assistant::ServerToolPart
|
|
23
|
+
def self.from_hash: (Hash[Symbol, untyped] | Riffer::Messages::Assistant::ServerToolPart) -> Riffer::Messages::Assistant::ServerToolPart
|
|
24
|
+
|
|
25
|
+
# --
|
|
26
|
+
# : (name: String, kind: Symbol, data: String, ?id: String?, ?format: String?) -> void
|
|
27
|
+
def initialize: (name: String, kind: Symbol, data: String, ?id: String?, ?format: String?) -> void
|
|
28
|
+
|
|
29
|
+
# --
|
|
30
|
+
# : () -> Hash[Symbol, untyped]
|
|
31
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
32
|
+
|
|
33
|
+
# --
|
|
34
|
+
# : (untyped) -> bool
|
|
35
|
+
def ==: (untyped) -> bool
|
|
36
|
+
|
|
37
|
+
# --
|
|
38
|
+
# : (untyped) -> bool
|
|
39
|
+
def eql?: (untyped) -> bool
|
|
40
|
+
|
|
41
|
+
# --
|
|
42
|
+
# : () -> Integer
|
|
43
|
+
def hash: () -> Integer
|
|
44
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Generated from lib/riffer/messages/assistant/text_part.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Riffer::Messages::Assistant::TextPart
|
|
4
|
+
attr_reader text: String
|
|
5
|
+
|
|
6
|
+
# The provider's whole block as JSON, kept when it carries more than the text (e.g. Anthropic
|
|
7
|
+
# +citations+), so the adapter that produced it can send it back unchanged.
|
|
8
|
+
attr_reader data: String?
|
|
9
|
+
|
|
10
|
+
attr_reader format: String?
|
|
11
|
+
|
|
12
|
+
# --
|
|
13
|
+
# : ((Hash[Symbol, untyped] | Riffer::Messages::Assistant::TextPart)) -> Riffer::Messages::Assistant::TextPart
|
|
14
|
+
def self.from_hash: (Hash[Symbol, untyped] | Riffer::Messages::Assistant::TextPart) -> Riffer::Messages::Assistant::TextPart
|
|
15
|
+
|
|
16
|
+
# --
|
|
17
|
+
# : (String, ?data: String?, ?format: String?) -> void
|
|
18
|
+
def initialize: (String, ?data: String?, ?format: String?) -> void
|
|
19
|
+
|
|
20
|
+
# --
|
|
21
|
+
# : () -> Hash[Symbol, untyped]
|
|
22
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
23
|
+
|
|
24
|
+
# --
|
|
25
|
+
# : (untyped) -> bool
|
|
26
|
+
def ==: (untyped) -> bool
|
|
27
|
+
|
|
28
|
+
# --
|
|
29
|
+
# : (untyped) -> bool
|
|
30
|
+
def eql?: (untyped) -> bool
|
|
31
|
+
|
|
32
|
+
# --
|
|
33
|
+
# : () -> Integer
|
|
34
|
+
def hash: () -> Integer
|
|
35
|
+
end
|
|
@@ -4,10 +4,20 @@ class Riffer::Messages::Assistant < Riffer::Messages::Base
|
|
|
4
4
|
# The other reasoning part types carry no prose.
|
|
5
5
|
REASONING_TEXT_TYPES: Array[Symbol]
|
|
6
6
|
|
|
7
|
+
PART_TAGS: Hash[singleton(Riffer::Messages::Assistant::TextPart) | singleton(Riffer::Messages::Assistant::ReasoningPart) | singleton(Riffer::Messages::Assistant::ToolCall) | singleton(Riffer::Messages::Assistant::ServerToolPart), Symbol]
|
|
8
|
+
|
|
7
9
|
# --
|
|
8
10
|
# : ((Hash[Symbol, untyped] | Riffer::Messages::Assistant)) -> Riffer::Messages::Assistant
|
|
9
11
|
def self.from_hash: (Hash[Symbol, untyped] | Riffer::Messages::Assistant) -> Riffer::Messages::Assistant
|
|
10
12
|
|
|
13
|
+
# --
|
|
14
|
+
# : ((Hash[Symbol, untyped] | Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart)) -> (Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart)
|
|
15
|
+
def self.part_from_hash: (Hash[Symbol, untyped] | Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart) -> (Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart)
|
|
16
|
+
|
|
17
|
+
# The turn in the order the provider produced it. +content+, +tool_calls+ and +reasoning+ are
|
|
18
|
+
# views over it.
|
|
19
|
+
attr_reader parts: Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
20
|
+
|
|
11
21
|
attr_reader tool_calls: Array[Riffer::Messages::Assistant::ToolCall]
|
|
12
22
|
|
|
13
23
|
attr_reader reasoning: Array[Riffer::Messages::Assistant::ReasoningPart]
|
|
@@ -20,18 +30,11 @@ class Riffer::Messages::Assistant < Riffer::Messages::Base
|
|
|
20
30
|
|
|
21
31
|
attr_reader finish_reason_raw: String?
|
|
22
32
|
|
|
33
|
+
# Without +parts:+, the parts are built in a fixed order: reasoning, then the content as one
|
|
34
|
+
# text part, then tool calls.
|
|
23
35
|
# --
|
|
24
|
-
# : (
|
|
25
|
-
|
|
26
|
-
# ?id: String?,
|
|
27
|
-
# ?tool_calls: Array[Riffer::Messages::Assistant::ToolCall],
|
|
28
|
-
# ?reasoning: Array[Riffer::Messages::Assistant::ReasoningPart],
|
|
29
|
-
# ?token_usage: Riffer::Providers::TokenUsage?,
|
|
30
|
-
# ?structured_output: Hash[Symbol, untyped]?,
|
|
31
|
-
# ?finish_reason: Symbol?,
|
|
32
|
-
# ?finish_reason_raw: String?
|
|
33
|
-
# ) -> void
|
|
34
|
-
def initialize: (String, ?id: String?, ?tool_calls: Array[Riffer::Messages::Assistant::ToolCall], ?reasoning: Array[Riffer::Messages::Assistant::ReasoningPart], ?token_usage: Riffer::Providers::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?, ?finish_reason: Symbol?, ?finish_reason_raw: String?) -> void
|
|
36
|
+
# : (?String?, ?id: String?, ?parts: Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]?, ?tool_calls: Array[Riffer::Messages::Assistant::ToolCall], ?reasoning: Array[Riffer::Messages::Assistant::ReasoningPart], ?token_usage: Riffer::Providers::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?, ?finish_reason: Symbol?, ?finish_reason_raw: String?) -> void
|
|
37
|
+
def initialize: (?String?, ?id: String?, ?parts: Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]?, ?tool_calls: Array[Riffer::Messages::Assistant::ToolCall], ?reasoning: Array[Riffer::Messages::Assistant::ReasoningPart], ?token_usage: Riffer::Providers::TokenUsage?, ?structured_output: Hash[Symbol, untyped]?, ?finish_reason: Symbol?, ?finish_reason_raw: String?) -> void
|
|
35
38
|
|
|
36
39
|
# --
|
|
37
40
|
# : () -> Symbol
|
|
@@ -60,4 +63,14 @@ class Riffer::Messages::Assistant < Riffer::Messages::Base
|
|
|
60
63
|
# --
|
|
61
64
|
# : () -> Hash[Symbol, untyped]
|
|
62
65
|
def to_h: () -> Hash[Symbol, untyped]
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# --
|
|
70
|
+
# : (String?, Array[Riffer::Messages::Assistant::ToolCall], Array[Riffer::Messages::Assistant::ReasoningPart]) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
71
|
+
def default_parts: (String?, Array[Riffer::Messages::Assistant::ToolCall], Array[Riffer::Messages::Assistant::ReasoningPart]) -> Array[Riffer::Messages::Assistant::TextPart | Riffer::Messages::Assistant::ReasoningPart | Riffer::Messages::Assistant::ToolCall | Riffer::Messages::Assistant::ServerToolPart]
|
|
72
|
+
|
|
73
|
+
# --
|
|
74
|
+
# : (Riffer::Messages::Assistant) -> bool
|
|
75
|
+
def described_by_fields?: (Riffer::Messages::Assistant) -> bool
|
|
63
76
|
end
|
|
@@ -11,10 +11,20 @@ class Riffer::Providers::AnthropicCompatible::MessagesAPI::Stream
|
|
|
11
11
|
|
|
12
12
|
@tools: Array[singleton(Riffer::Tool)]
|
|
13
13
|
|
|
14
|
+
# Each server tool has its own result type (web search run from code execution returns
|
|
15
|
+
# +code_execution_tool_result+ blocks too), and the API rejects a server_tool_use sent back
|
|
16
|
+
# without its result. +mcp_tool_result+ pairs with +mcp_tool_use+, which riffer drops, so
|
|
17
|
+
# its result is dropped too.
|
|
18
|
+
SERVER_TOOL_RESULT_TYPE: Regexp
|
|
19
|
+
|
|
14
20
|
# --
|
|
15
21
|
# : (Hash[Symbol, untyped]) -> Riffer::Messages::Assistant::ReasoningPart?
|
|
16
22
|
def self.reasoning_part: (Hash[Symbol, untyped]) -> Riffer::Messages::Assistant::ReasoningPart?
|
|
17
23
|
|
|
24
|
+
# --
|
|
25
|
+
# : (Hash[Symbol, untyped]) -> Riffer::Messages::Assistant::ServerToolPart
|
|
26
|
+
def self.server_tool_part: (Hash[Symbol, untyped]) -> Riffer::Messages::Assistant::ServerToolPart
|
|
27
|
+
|
|
18
28
|
# --
|
|
19
29
|
# : (tools: Array[singleton(Riffer::Tool)]) -> void
|
|
20
30
|
def initialize: (tools: Array[singleton(Riffer::Tool)]) -> void
|