module Riffer::Rig::ACP::Mapper
Constants
- ANSWER_FIELD
- CONFIRMED
- CONFIRM_OPTIONS
- TOOL_KINDS
Public Instance Methods
(Array[String] options) → Array[::ACP::Types::PermissionOption]
Source
# File lib/riffer/rig/acp/mapper.rb, line 121 def choices(options) options.map do |option| ::ACP::Types::PermissionOption.new( option_id: option, name: option, kind: ::ACP::Types::PermissionOptionKind::ALLOW_ONCE ) end end
(String session_id, String question) → ::ACP::Types::CreateElicitationRequest
Source
# File lib/riffer/rig/acp/mapper.rb, line 181 def elicitation_request(session_id, question) ::ACP::Types::CreateElicitationRequest.new( message: question, mode: ::ACP::Types::CreateElicitationRequest::Mode::Form.new( requested_schema: ::ACP::Types::ElicitationSchema.new( type: ::ACP::Types::ElicitationSchemaType::OBJECT, properties: { ANSWER_FIELD => ::ACP::Types::ElicitationPropertySchema::StringPropertySchema.new(title: question) }, required: [ANSWER_FIELD] ), scope: ::ACP::Types::ElicitationSessionScope.new(session_id: session_id) ) ) end
@rbs session_id: String @rbs question: String @rbs return: ::ACP::Types::CreateElicitationRequest
(::ACP::Types::CreateElicitationResponse | ::ACP::RequestError response) → String?
Source
# File lib/riffer/rig/acp/mapper.rb, line 199 def elicited_answer(response) return nil unless response.is_a?(::ACP::Types::CreateElicitationResponse) action = response.action return nil unless action.is_a?(::ACP::Types::CreateElicitationResponse::Action::Accept) answer = action.content&.fetch(ANSWER_FIELD, nil) answer if answer.is_a?(String) end
@rbs response: ::ACP::Types::CreateElicitationResponse | ::ACP::RequestError @rbs return: String?
(Riffer::Rig::Runtime::JobCompletion completion) → ::ACP::Types::SessionUpdate::AgentMessageChunk
Source
# File lib/riffer/rig/acp/mapper.rb, line 65 def job_completion(completion) notice("Background job #{completion.job_id} #{ending(completion)}: #{completion.command}") end
@rbs completion: Riffer::Rig::Runtime::JobCompletion @rbs return: ::ACP::Types::SessionUpdate::AgentMessageChunk
() → ::ACP::Types::SessionUpdate::AgentMessageChunk
Source
# File lib/riffer/rig/acp/mapper.rb, line 57 def job_exit # ACP has no update for a job exit notice, and without a break the replies # either side of one read as a single message. message_chunk("\n\n") end
@rbs return: ::ACP::Types::SessionUpdate::AgentMessageChunk
(String content) → ::ACP::Types::SessionUpdate::AgentMessageChunk
Source
# File lib/riffer/rig/acp/mapper.rb, line 44 def message_chunk(content) ::ACP::Types::SessionUpdate::AgentMessageChunk.new(content: text_block(content)) end
@rbs content: String @rbs return: ::ACP::Types::SessionUpdate::AgentMessageChunk
(String text) → ::ACP::Types::SessionUpdate::AgentMessageChunk
Source
# File lib/riffer/rig/acp/mapper.rb, line 50 def notice(text) # ACP has no update for a notice, and without blank lines around it a # notice runs into the reply and into the next notice. message_chunk("\n\n#{text}\n\n") end
@rbs text: String @rbs return: ::ACP::Types::SessionUpdate::AgentMessageChunk
(String tool_call_id, String question) → ::ACP::Types::SessionUpdate::ToolCall
Source
# File lib/riffer/rig/acp/mapper.rb, line 132 def permission_call(tool_call_id, question) ::ACP::Types::SessionUpdate::ToolCall.new( tool_call_id: tool_call_id, title: question, kind: ::ACP::Types::ToolKind::OTHER, status: ::ACP::Types::ToolCallStatus::PENDING ) end
@rbs tool_call_id: String @rbs question: String @rbs return: ::ACP::Types::SessionUpdate::ToolCall
(String tool_call_id, String? selected) → ::ACP::Types::SessionUpdate::ToolCallUpdate
Source
# File lib/riffer/rig/acp/mapper.rb, line 171 def permission_done(tool_call_id, selected) ::ACP::Types::SessionUpdate::ToolCallUpdate.new( tool_call_id: tool_call_id, status: selected ? ::ACP::Types::ToolCallStatus::COMPLETED : ::ACP::Types::ToolCallStatus::FAILED ) end
@rbs tool_call_id: String @rbs selected: String? @rbs return: ::ACP::Types::SessionUpdate::ToolCallUpdate
(String session_id, String tool_call_id, String question, Array[::ACP::Types::PermissionOption] options) → ::ACP::Types::RequestPermissionRequest
Source
# File lib/riffer/rig/acp/mapper.rb, line 146 def permission_request(session_id, tool_call_id, question, options) ::ACP::Types::RequestPermissionRequest.new( session_id: session_id, tool_call: ::ACP::Types::ToolCallUpdate.new( tool_call_id: tool_call_id, title: question, kind: ::ACP::Types::ToolKind::OTHER, status: ::ACP::Types::ToolCallStatus::PENDING ), options: options ) end
@rbs session_id: String @rbs tool_call_id: String @rbs question: String @rbs options: Array @rbs return: ::ACP::Types::RequestPermissionRequest
(Array[::ACP::Types::ContentBlock::t] blocks) → String
Source
# File lib/riffer/rig/acp/mapper.rb, line 26 def prompt_text(blocks) blocks.filter_map { |block| prompt_text_of(block) }.join("\n\n") end
Text and resource links are ACP’s must-support prompt blocks; the client cannot send the others unless the agent advertised them. @rbs blocks: Array @rbs return: String
(Hash[Symbol, untyped] message) → ::ACP::Types::SessionUpdate::t?
Source
# File lib/riffer/rig/acp/mapper.rb, line 71 def replay_of(message) return job_exit if message[Riffer::Rig::Runtime::JobNotification::MARKER] case message[:role] when 'user' then ::ACP::Types::SessionUpdate::UserMessageChunk.new(content: text_block(message[:content].to_s)) when 'assistant' then message_chunk(message[:content].to_s) unless message[:content].to_s.strip.empty? when 'tool' then replayed_tool_call(message) end end
@rbs message: Hash[Symbol, untyped] @rbs return: ::ACP::Types::SessionUpdate::t?
(::ACP::Types::RequestPermissionResponse | ::ACP::RequestError response) → String?
Source
# File lib/riffer/rig/acp/mapper.rb, line 161 def selected_option(response) return nil unless response.is_a?(::ACP::Types::RequestPermissionResponse) outcome = response.outcome outcome.option_id if outcome.is_a?(::ACP::Types::RequestPermissionOutcome::Selected) end
@rbs response: ::ACP::Types::RequestPermissionResponse | ::ACP::RequestError @rbs return: String?
(Symbol stop_reason) → String
Source
# File lib/riffer/rig/acp/mapper.rb, line 108 def stop_reason_of(stop_reason) case stop_reason when :completed then ::ACP::Types::StopReason::END_TURN when Riffer::Rig::Runtime::StopReason::INTERRUPT_CANCELLED then ::ACP::Types::StopReason::CANCELLED when :max_steps then ::ACP::Types::StopReason::MAX_TURN_REQUESTS else stopped = Riffer::Rig::Runtime::StopReason::STOPPED_WITHOUT_COMPLETING.include?(stop_reason) stopped ? ::ACP::Types::StopReason::MAX_TOKENS : ::ACP::Types::StopReason::REFUSAL end end
riffer’s failure reasons (:error, :other, :guardrail_blocked) have no ACP counterpart; refusal is the closest signal that the turn did not complete. @rbs stop_reason: Symbol @rbs return: String
(Riffer::StreamEvents::ToolCallDone event) → ::ACP::Types::SessionUpdate::ToolCall
Source
# File lib/riffer/rig/acp/mapper.rb, line 83 def tool_call(event) ::ACP::Types::SessionUpdate::ToolCall.new( tool_call_id: event.call_id, title: "#{event.name}(#{event.arguments})", name: event.name, kind: TOOL_KINDS.fetch(event.name, ::ACP::Types::ToolKind::OTHER), status: ::ACP::Types::ToolCallStatus::IN_PROGRESS ) end
@rbs event: Riffer::StreamEvents::ToolCallDone @rbs return: ::ACP::Types::SessionUpdate::ToolCall
(Riffer::Rig::Events::AfterToolCall event) → ::ACP::Types::SessionUpdate::ToolCallUpdate
Source
# File lib/riffer/rig/acp/mapper.rb, line 95 def tool_call_done(event) result = event.result ::ACP::Types::SessionUpdate::ToolCallUpdate.new( tool_call_id: event.call_id, status: result.error? ? ::ACP::Types::ToolCallStatus::FAILED : ::ACP::Types::ToolCallStatus::COMPLETED, content: tool_content(result.content) ) end
@rbs event: Riffer::Rig::Events::AfterToolCall @rbs return: ::ACP::Types::SessionUpdate::ToolCallUpdate
(::Riffer::StreamEvents::Base | Riffer::Rig::Events::_Event event) → ::ACP::Types::SessionUpdate::t?
Source
# File lib/riffer/rig/acp/mapper.rb, line 32 def update_for(event) case event when Riffer::StreamEvents::TextDelta then message_chunk(event.content) when Riffer::Rig::Events::CommandOutput then message_chunk(event.text) when Riffer::StreamEvents::ToolCallDone then tool_call(event) when Riffer::Rig::Events::AfterToolCall then tool_call_done(event) when Riffer::Rig::Events::JobExit then job_exit end end
@rbs event: ::Riffer::StreamEvents::Base | Riffer::Rig::Events::_Event @rbs return: ::ACP::Types::SessionUpdate::t?