Class: Opencode::Prompts
- Inherits:
-
Object
- Object
- Opencode::Prompts
- Defined in:
- lib/opencode/prompts.rb
Overview
Per-Reply registry of interactive prompts (questions + permissions) opencode has asked the user but not yet resolved. Lives on Opencode::Reply for the lifetime of one streaming turn.
Two access patterns:
* by request id ("que_..." or "per_...") — for the controller
posting a user's answer back.
* by {message_id, call_id} — for the order-race fix where
`question.asked` may arrive before the matching tool part.
The registry also exposes a ‘prompt_blocked?` predicate that Opencode::Client uses to suspend the SSE deadline check while a healthy wait is in progress.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #any_pending? ⇒ Boolean (also: #prompt_blocked?)
- #asked_at(request_id) ⇒ Object
- #each_pending ⇒ Object
-
#find(request_id) ⇒ Object
Returns the raw request hash (not the Entry wrapper) so callers don’t depend on internal bookkeeping shape.
-
#find_by_call(message_id:, call_id:) ⇒ Object
Returns the raw request hash, same shape as #find.
-
#initialize ⇒ Prompts
constructor
A new instance of Prompts.
- #record_permission(request) ⇒ Object
- #record_question(request) ⇒ Object
- #resolve(request_id) ⇒ Object
Constructor Details
#initialize ⇒ Prompts
Returns a new instance of Prompts.
21 22 23 24 |
# File 'lib/opencode/prompts.rb', line 21 def initialize @entries = {} @by_call = {} end |
Instance Method Details
#any_pending? ⇒ Boolean Also known as: prompt_blocked?
60 61 62 |
# File 'lib/opencode/prompts.rb', line 60 def any_pending? @entries.any? end |
#asked_at(request_id) ⇒ Object
65 66 67 |
# File 'lib/opencode/prompts.rb', line 65 def asked_at(request_id) @entries[request_id]&.asked_at end |
#each_pending ⇒ Object
56 57 58 |
# File 'lib/opencode/prompts.rb', line 56 def each_pending @entries.each_value { |entry| yield(entry.kind, entry.request) } end |
#find(request_id) ⇒ Object
Returns the raw request hash (not the Entry wrapper) so callers don’t depend on internal bookkeeping shape.
36 37 38 |
# File 'lib/opencode/prompts.rb', line 36 def find(request_id) @entries[request_id]&.request end |
#find_by_call(message_id:, call_id:) ⇒ Object
Returns the raw request hash, same shape as #find.
41 42 43 44 |
# File 'lib/opencode/prompts.rb', line 41 def find_by_call(message_id:, call_id:) key = call_key(, call_id) @by_call[key]&.request end |
#record_permission(request) ⇒ Object
30 31 32 |
# File 'lib/opencode/prompts.rb', line 30 def (request) record(:permission, request) end |
#record_question(request) ⇒ Object
26 27 28 |
# File 'lib/opencode/prompts.rb', line 26 def record_question(request) record(:question, request) end |
#resolve(request_id) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/opencode/prompts.rb', line 46 def resolve(request_id) entry = @entries.delete(request_id) return unless entry tool = entry.request[:tool] return unless tool @by_call.delete(call_key(tool[:messageID], tool[:callID])) end |