riffer 0.54.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/.claude/rules/rbs-inline.md +6 -6
- data/.release-please-manifest.json +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +46 -0
- data/README.md +26 -1
- data/Steepfile +2 -2
- data/UPGRADING.md +3 -0
- data/docs/AGENTS.md +37 -12
- data/docs/AGENT_LIFECYCLE.md +1 -1
- data/docs/CATALOG.md +8 -8
- data/docs/CONFIGURATION.md +95 -17
- data/docs/GUARDRAILS.md +2 -0
- data/docs/MCP.md +3 -4
- data/docs/MESSAGES.md +112 -15
- data/docs/STABILITY.md +32 -0
- data/docs/STREAM_EVENTS.md +17 -1
- data/docs/TESTING.md +22 -1
- data/docs/TOOLS.md +11 -11
- data/docs/TRACING.md +1 -1
- data/docs/providers/AMAZON_BEDROCK.md +3 -1
- data/docs/providers/ANTHROPIC.md +44 -44
- data/docs/providers/CUSTOM_PROVIDERS.md +59 -0
- data/docs/providers/GEMINI.md +76 -26
- data/docs/providers/GOOGLE_CLOUD.md +363 -0
- data/docs/providers/MOCK_PROVIDER.md +2 -0
- data/docs/providers/OPENAI.md +3 -1
- data/docs/providers/PROVIDERS.md +30 -18
- data/docs-site/manifest.yml +6 -0
- data/lib/riffer/agent/run.rb +28 -13
- data/lib/riffer/agent/session.rb +33 -10
- data/lib/riffer/agent/structured_output.rb +6 -1
- data/lib/riffer/config/anthropic.rb +9 -0
- data/lib/riffer/config/future.rb +53 -0
- data/lib/riffer/config/gemini.rb +9 -0
- data/lib/riffer/config/google_cloud.rb +38 -0
- data/lib/riffer/config/pricing.rb +5 -15
- data/lib/riffer/config.rb +19 -0
- data/lib/riffer/deprecation/event.rb +25 -0
- data/lib/riffer/deprecation.rb +60 -0
- data/lib/riffer/http/client.rb +141 -0
- data/lib/riffer/http.rb +5 -0
- data/lib/riffer/mcp/client.rb +0 -1
- 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/params/any_of.rb +37 -9
- data/lib/riffer/params/param.rb +35 -14
- data/lib/riffer/params.rb +34 -19
- data/lib/riffer/providers/amazon_bedrock.rb +38 -5
- data/lib/riffer/providers/anthropic/client.rb +49 -0
- data/lib/riffer/providers/anthropic.rb +19 -452
- data/lib/riffer/providers/anthropic_compatible/messages_api/stream.rb +219 -0
- data/lib/riffer/providers/anthropic_compatible/messages_api.rb +315 -0
- data/lib/riffer/providers/anthropic_compatible.rb +5 -0
- data/lib/riffer/providers/anthropic_vertex.rb +66 -0
- data/lib/riffer/providers/base.rb +19 -13
- data/lib/riffer/providers/gemini/client.rb +17 -85
- data/lib/riffer/providers/gemini.rb +213 -81
- data/lib/riffer/providers/google_cloud/client.rb +106 -0
- data/lib/riffer/providers/google_cloud.rb +99 -0
- data/lib/riffer/providers/open_ai.rb +21 -16
- data/lib/riffer/providers/repository.rb +2 -0
- 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/wire/sse.rb +51 -0
- data/lib/riffer/wire.rb +31 -0
- data/lib/riffer.rb +20 -0
- data/rbs_collection.lock.yaml +24 -4
- data/sig/_private/faraday.rbs +8 -0
- data/sig/_private/googleauth.rbs +7 -0
- data/sig/generated/riffer/agent/run.rbs +5 -0
- data/sig/generated/riffer/agent/session.rbs +6 -0
- data/sig/generated/riffer/config/anthropic.rbs +6 -0
- data/sig/generated/riffer/config/future.rbs +29 -0
- data/sig/generated/riffer/config/gemini.rbs +6 -0
- data/sig/generated/riffer/config/google_cloud.rbs +28 -0
- data/sig/generated/riffer/config/pricing.rbs +0 -9
- data/sig/generated/riffer/config.rbs +10 -0
- data/sig/generated/riffer/deprecation/event.rbs +17 -0
- data/sig/generated/riffer/deprecation.rbs +27 -0
- data/sig/generated/riffer/http/client.rbs +59 -0
- data/sig/generated/riffer/http.rbs +4 -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/params/any_of.rbs +13 -5
- data/sig/generated/riffer/params/param.rbs +10 -5
- data/sig/generated/riffer/params.rbs +8 -4
- data/sig/generated/riffer/providers/amazon_bedrock.rbs +14 -2
- data/sig/generated/riffer/providers/anthropic/client.rbs +34 -0
- data/sig/generated/riffer/providers/anthropic.rbs +5 -124
- data/sig/generated/riffer/providers/anthropic_compatible/messages_api/stream.rbs +81 -0
- data/sig/generated/riffer/providers/anthropic_compatible/messages_api.rbs +108 -0
- data/sig/generated/riffer/providers/anthropic_compatible.rbs +4 -0
- data/sig/generated/riffer/providers/anthropic_vertex.rbs +45 -0
- data/sig/generated/riffer/providers/base.rbs +5 -0
- data/sig/generated/riffer/providers/gemini/client.rbs +11 -34
- data/sig/generated/riffer/providers/gemini.rbs +66 -4
- data/sig/generated/riffer/providers/google_cloud/client.rbs +71 -0
- data/sig/generated/riffer/providers/google_cloud.rbs +64 -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/wire/sse.rbs +23 -0
- data/sig/generated/riffer/wire.rbs +17 -0
- data/sig/generated/riffer.rbs +15 -0
- data/sig/manual/riffer/deprecation.rbs +5 -0
- data/sig/manual/riffer/providers/anthropic_compatible/messages_api.rbs +8 -0
- data/sig/manual/riffer/providers/gemini.rbs +8 -0
- data/sig/manual/riffer/providers/google_cloud.rbs +8 -0
- data/sig/manual/riffer/wire.rbs +5 -0
- metadata +76 -5
- data/sig/_private/anthropic.rbs +0 -17
- data/sig/_private/riffer/providers/anthropic.rbs +0 -6
- data/sig/_private/riffer/providers/gemini.rbs +0 -7
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
# Gemini models on Gemini Enterprise Agent Platform (formerly Vertex AI). The
|
|
5
|
+
# request and response bodies match the Gemini Developer API's, so this only
|
|
6
|
+
# swaps the transport, the resource paths and the structured output field.
|
|
7
|
+
class Riffer::Providers::GoogleCloud < Riffer::Providers::Gemini
|
|
8
|
+
# Agent Platform model ids may carry an +@version+ suffix.
|
|
9
|
+
VALID_MODEL_PATTERN = /\A[a-zA-Z0-9._@-]+\z/ #: Regexp
|
|
10
|
+
|
|
11
|
+
REASONING_FORMAT = "google-cloud-generate-content-v1" #: String
|
|
12
|
+
|
|
13
|
+
# Agent Platform label keys and values: at most 63 characters of lowercase
|
|
14
|
+
# letters, digits, underscores and dashes; keys start with a letter.
|
|
15
|
+
LABEL_MAX_LENGTH = 63 #: Integer
|
|
16
|
+
LABEL_INVALID_CHARACTERS = /[^\p{Ll}\p{Lo}\p{N}_-]/ #: Regexp
|
|
17
|
+
|
|
18
|
+
#--
|
|
19
|
+
#: () -> String
|
|
20
|
+
def self.semconv_provider_name
|
|
21
|
+
"gcp.vertex_ai"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
#--
|
|
27
|
+
#: () -> untyped
|
|
28
|
+
def global_client
|
|
29
|
+
Riffer.config.google_cloud.client
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#--
|
|
33
|
+
#: () -> untyped
|
|
34
|
+
def build_client
|
|
35
|
+
Riffer::Providers::GoogleCloud::Client.from_config(Riffer.config.google_cloud)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Tags go out as request labels, merged over any +labels+ model option.
|
|
39
|
+
#--
|
|
40
|
+
#: (Array[Riffer::Messages::Base], String?, Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
|
|
41
|
+
def build_request_params(messages, model, options)
|
|
42
|
+
params = super(messages, model, options.except(:labels))
|
|
43
|
+
labels = (options[:labels] || {}).transform_keys(&:to_s).merge(tag_labels(options[:tags] || {}))
|
|
44
|
+
params[:labels] = labels unless labels.empty?
|
|
45
|
+
params
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Rewrites tags into valid labels (downcased, invalid characters replaced by
|
|
49
|
+
# an underscore, cut to 63 characters) and drops keys that don't start with
|
|
50
|
+
# a letter, so a tag like agent: "support/triage_agent" can't fail the call.
|
|
51
|
+
#--
|
|
52
|
+
#: (Hash[untyped, untyped]) -> Hash[String, String]
|
|
53
|
+
def tag_labels(tags)
|
|
54
|
+
labels = {} #: Hash[String, String]
|
|
55
|
+
tags.each do |key, value|
|
|
56
|
+
next if value.nil?
|
|
57
|
+
|
|
58
|
+
label_key = to_label(key)
|
|
59
|
+
labels[label_key] = to_label(value) if label_key.match?(/\A\p{L}/)
|
|
60
|
+
end
|
|
61
|
+
labels
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#--
|
|
65
|
+
#: (untyped) -> String
|
|
66
|
+
def to_label(value)
|
|
67
|
+
value.to_s.downcase.gsub(LABEL_INVALID_CHARACTERS, "_")[0, LABEL_MAX_LENGTH].to_s
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#--
|
|
71
|
+
#: () -> String
|
|
72
|
+
def reasoning_format
|
|
73
|
+
REASONING_FORMAT
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Agent Platform declares responseFormat as a repeated field.
|
|
77
|
+
#--
|
|
78
|
+
#: (Hash[Symbol, untyped]) -> Hash[Symbol, untyped]
|
|
79
|
+
def structured_output_config(json_schema)
|
|
80
|
+
{ responseFormat: [{ text: { mimeType: "APPLICATION_JSON", schema: json_schema } }] }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
#--
|
|
84
|
+
#: (String, String) -> String
|
|
85
|
+
def api_path(model, method)
|
|
86
|
+
validate_model!(model)
|
|
87
|
+
"publishers/google/models/#{model}:#{method}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
#--
|
|
91
|
+
#: (String) -> void
|
|
92
|
+
def validate_model!(model)
|
|
93
|
+
return if model.match?(VALID_MODEL_PATTERN)
|
|
94
|
+
|
|
95
|
+
raise Riffer::ArgumentError,
|
|
96
|
+
"Invalid model name: #{model.inspect}. Model must contain only alphanumeric characters, " \
|
|
97
|
+
"hyphens, dots, underscores, and @."
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -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
|
|
|
@@ -10,8 +10,10 @@ module Riffer::Providers::Repository
|
|
|
10
10
|
REPO = {
|
|
11
11
|
amazon_bedrock: -> { Riffer::Providers::AmazonBedrock },
|
|
12
12
|
anthropic: -> { Riffer::Providers::Anthropic },
|
|
13
|
+
anthropic_vertex: -> { Riffer::Providers::AnthropicVertex },
|
|
13
14
|
azure_openai: -> { Riffer::Providers::AzureOpenAI },
|
|
14
15
|
gemini: -> { Riffer::Providers::Gemini },
|
|
16
|
+
google_cloud: -> { Riffer::Providers::GoogleCloud },
|
|
15
17
|
openai: -> { Riffer::Providers::OpenAI },
|
|
16
18
|
openrouter: -> { Riffer::Providers::OpenRouter },
|
|
17
19
|
mock: -> { Riffer::Providers::Mock },
|
|
@@ -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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
class Riffer::Wire::SSE
|
|
5
|
+
# @rbs @buffer: String
|
|
6
|
+
# @rbs @data: Array[String]
|
|
7
|
+
# @rbs @event: String?
|
|
8
|
+
|
|
9
|
+
#--
|
|
10
|
+
#: () -> void
|
|
11
|
+
def initialize
|
|
12
|
+
@buffer = +""
|
|
13
|
+
@data = []
|
|
14
|
+
@event = nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#--
|
|
18
|
+
#: (String) { (String, String?) -> void } -> void
|
|
19
|
+
def feed(chunk, &)
|
|
20
|
+
@buffer << chunk
|
|
21
|
+
|
|
22
|
+
# Lines end in LF or CRLF. The SSE spec also allows a bare CR, which no
|
|
23
|
+
# supported provider sends.
|
|
24
|
+
while (line_end = @buffer.index("\n"))
|
|
25
|
+
line = @buffer.slice!(0, line_end + 1).to_s.chomp
|
|
26
|
+
process_line(line, &)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
#--
|
|
33
|
+
#: (String) { (String, String?) -> void } -> void
|
|
34
|
+
def process_line(line)
|
|
35
|
+
if line.empty?
|
|
36
|
+
yield(@data.join("\n"), @event) unless @data.empty?
|
|
37
|
+
@data = []
|
|
38
|
+
@event = nil
|
|
39
|
+
return
|
|
40
|
+
end
|
|
41
|
+
return if line.start_with?(":")
|
|
42
|
+
|
|
43
|
+
field, value = line.split(":", 2)
|
|
44
|
+
value = value.to_s.delete_prefix(" ")
|
|
45
|
+
|
|
46
|
+
case field
|
|
47
|
+
when "data" then @data << value
|
|
48
|
+
when "event" then @event = value
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/riffer/wire.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Riffer::Wire
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
TOOL_NAME_SEPARATOR = "__" #: String
|
|
10
|
+
|
|
11
|
+
#--
|
|
12
|
+
#: (String) -> String
|
|
13
|
+
def encode_tool_name(name)
|
|
14
|
+
name.gsub("/", TOOL_NAME_SEPARATOR)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#--
|
|
18
|
+
#: (String, tools: Array[singleton(Riffer::Tool)]) -> String
|
|
19
|
+
def decode_tool_name(wire_name, tools:)
|
|
20
|
+
tool = tools.find { |t| encode_tool_name(t.name) == wire_name }
|
|
21
|
+
tool ? tool.name : wire_name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#--
|
|
25
|
+
#: (String) -> Hash[String, untyped]
|
|
26
|
+
def parse_tool_arguments(arguments)
|
|
27
|
+
return {} if arguments.empty?
|
|
28
|
+
|
|
29
|
+
JSON.parse(arguments)
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/riffer.rb
CHANGED
|
@@ -8,6 +8,9 @@ loader.inflector.inflect(
|
|
|
8
8
|
"open_ai" => "OpenAI",
|
|
9
9
|
"azure_open_ai" => "AzureOpenAI",
|
|
10
10
|
"open_router" => "OpenRouter",
|
|
11
|
+
"sse" => "SSE",
|
|
12
|
+
"http" => "HTTP",
|
|
13
|
+
"messages_api" => "MessagesAPI",
|
|
11
14
|
)
|
|
12
15
|
# Test-framework wiring a consumer requires by hand; neither file defines the
|
|
13
16
|
# constant its path implies, and both reference framework constants riffer
|
|
@@ -29,6 +32,21 @@ module Riffer
|
|
|
29
32
|
|
|
30
33
|
class ValidationError < Error; end
|
|
31
34
|
|
|
35
|
+
# A provider answered with a non-success status, or sent an in-stream error
|
|
36
|
+
# event (+status+ is nil then). +body+ is the raw response text.
|
|
37
|
+
class APIError < Error
|
|
38
|
+
attr_reader :status #: Integer? # @dynamic status
|
|
39
|
+
attr_reader :body #: String? # @dynamic body
|
|
40
|
+
|
|
41
|
+
#--
|
|
42
|
+
#: (?String?, ?status: Integer?, ?body: String?) -> void
|
|
43
|
+
def initialize(message = nil, status: nil, body: nil)
|
|
44
|
+
super(message)
|
|
45
|
+
@status = status
|
|
46
|
+
@body = body
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
32
50
|
# Rescue it in the tool to clean up; otherwise it becomes a
|
|
33
51
|
# +:timeout_error+ response.
|
|
34
52
|
class TimeoutError < Error; end
|
|
@@ -56,6 +74,8 @@ module Riffer
|
|
|
56
74
|
|
|
57
75
|
class DuplicateIdentifierError < Error; end
|
|
58
76
|
|
|
77
|
+
class DeprecationError < Error; end
|
|
78
|
+
|
|
59
79
|
#--
|
|
60
80
|
#: () -> Riffer::Config
|
|
61
81
|
def config
|
data/rbs_collection.lock.yaml
CHANGED
|
@@ -9,10 +9,6 @@ gems:
|
|
|
9
9
|
revision: 3913b7dffb65bdffdfe5cb9095108f932e85433b
|
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
11
|
repo_dir: gems
|
|
12
|
-
- name: anthropic
|
|
13
|
-
version: 1.76.0
|
|
14
|
-
source:
|
|
15
|
-
type: rubygems
|
|
16
12
|
- name: ast
|
|
17
13
|
version: '2.4'
|
|
18
14
|
source:
|
|
@@ -117,6 +113,14 @@ gems:
|
|
|
117
113
|
version: '0'
|
|
118
114
|
source:
|
|
119
115
|
type: stdlib
|
|
116
|
+
- name: googleauth
|
|
117
|
+
version: '1.11'
|
|
118
|
+
source:
|
|
119
|
+
type: git
|
|
120
|
+
name: ruby/gem_rbs_collection
|
|
121
|
+
revision: 3913b7dffb65bdffdfe5cb9095108f932e85433b
|
|
122
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
123
|
+
repo_dir: gems
|
|
120
124
|
- name: hashdiff
|
|
121
125
|
version: '1.1'
|
|
122
126
|
source:
|
|
@@ -137,6 +141,14 @@ gems:
|
|
|
137
141
|
version: '0'
|
|
138
142
|
source:
|
|
139
143
|
type: stdlib
|
|
144
|
+
- name: jwt
|
|
145
|
+
version: '2.5'
|
|
146
|
+
source:
|
|
147
|
+
type: git
|
|
148
|
+
name: ruby/gem_rbs_collection
|
|
149
|
+
revision: 3913b7dffb65bdffdfe5cb9095108f932e85433b
|
|
150
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
151
|
+
repo_dir: gems
|
|
140
152
|
- name: language_server-protocol
|
|
141
153
|
version: 3.17.0.6
|
|
142
154
|
source:
|
|
@@ -265,6 +277,14 @@ gems:
|
|
|
265
277
|
version: '0'
|
|
266
278
|
source:
|
|
267
279
|
type: stdlib
|
|
280
|
+
- name: signet
|
|
281
|
+
version: '0.19'
|
|
282
|
+
source:
|
|
283
|
+
type: git
|
|
284
|
+
name: ruby/gem_rbs_collection
|
|
285
|
+
revision: 3913b7dffb65bdffdfe5cb9095108f932e85433b
|
|
286
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
287
|
+
repo_dir: gems
|
|
268
288
|
- name: singleton
|
|
269
289
|
version: '0'
|
|
270
290
|
source:
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# The collection's faraday 2.7 stubs declare Request#options= but not the
|
|
2
|
+
# reader that streaming needs to set on_data. Loaded only for riffer's own
|
|
3
|
+
# Steep run (consumers skip sig/_private).
|
|
4
|
+
module Faraday
|
|
5
|
+
class Request
|
|
6
|
+
def options: () -> Faraday::RequestOptions
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -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
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
class Riffer::Config::Anthropic
|
|
4
4
|
attr_reader api_key: String?
|
|
5
5
|
|
|
6
|
+
attr_reader base_url: String?
|
|
7
|
+
|
|
6
8
|
attr_accessor client: untyped
|
|
7
9
|
|
|
8
10
|
# --
|
|
@@ -12,4 +14,8 @@ class Riffer::Config::Anthropic
|
|
|
12
14
|
# --
|
|
13
15
|
# : (untyped) -> void
|
|
14
16
|
def api_key=: (untyped) -> void
|
|
17
|
+
|
|
18
|
+
# --
|
|
19
|
+
# : (untyped) -> void
|
|
20
|
+
def base_url=: (untyped) -> void
|
|
15
21
|
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,6 +3,8 @@
|
|
|
3
3
|
class Riffer::Config::Gemini
|
|
4
4
|
attr_reader api_key: String?
|
|
5
5
|
|
|
6
|
+
attr_reader base_url: String?
|
|
7
|
+
|
|
6
8
|
attr_accessor client: untyped
|
|
7
9
|
|
|
8
10
|
# --
|
|
@@ -12,4 +14,8 @@ class Riffer::Config::Gemini
|
|
|
12
14
|
# --
|
|
13
15
|
# : (untyped) -> void
|
|
14
16
|
def api_key=: (untyped) -> void
|
|
17
|
+
|
|
18
|
+
# --
|
|
19
|
+
# : (untyped) -> void
|
|
20
|
+
def base_url=: (untyped) -> void
|
|
15
21
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Generated from lib/riffer/config/google_cloud.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
class Riffer::Config::GoogleCloud
|
|
4
|
+
attr_reader project_id: String?
|
|
5
|
+
|
|
6
|
+
# The default +"global"+ endpoint routes requests to any region, so it
|
|
7
|
+
# carries no data-residency guarantee.
|
|
8
|
+
attr_reader location: String
|
|
9
|
+
|
|
10
|
+
# A googleauth credentials object; +nil+ resolves Application Default
|
|
11
|
+
# Credentials.
|
|
12
|
+
attr_accessor credentials: untyped
|
|
13
|
+
|
|
14
|
+
attr_accessor client: untyped
|
|
15
|
+
|
|
16
|
+
# --
|
|
17
|
+
# : () -> void
|
|
18
|
+
def initialize: () -> void
|
|
19
|
+
|
|
20
|
+
# --
|
|
21
|
+
# : (untyped) -> void
|
|
22
|
+
def project_id=: (untyped) -> void
|
|
23
|
+
|
|
24
|
+
# +nil+ restores the +"global"+ default.
|
|
25
|
+
# --
|
|
26
|
+
# : (untyped) -> void
|
|
27
|
+
def location=: (untyped) -> void
|
|
28
|
+
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
|
|
@@ -13,6 +13,8 @@ class Riffer::Config
|
|
|
13
13
|
|
|
14
14
|
attr_reader gemini: Riffer::Config::Gemini
|
|
15
15
|
|
|
16
|
+
attr_reader google_cloud: Riffer::Config::GoogleCloud
|
|
17
|
+
|
|
16
18
|
attr_reader openai: Riffer::Config::OpenAI
|
|
17
19
|
|
|
18
20
|
attr_reader openrouter: Riffer::Config::OpenRouter
|
|
@@ -33,6 +35,8 @@ class Riffer::Config
|
|
|
33
35
|
|
|
34
36
|
attr_reader files: Riffer::Config::Files
|
|
35
37
|
|
|
38
|
+
attr_reader future: Riffer::Config::Future
|
|
39
|
+
|
|
36
40
|
# @deprecated Use +catalog_files+.
|
|
37
41
|
attr_reader pricing: Riffer::Config::Pricing
|
|
38
42
|
|
|
@@ -58,6 +62,12 @@ class Riffer::Config
|
|
|
58
62
|
# : (Symbol) -> void
|
|
59
63
|
def message_id_strategy=: (Symbol) -> void
|
|
60
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
|
+
|
|
61
71
|
# --
|
|
62
72
|
# : () -> void
|
|
63
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
|