Class: RubyClaude::Session
- Inherits:
-
Object
- Object
- RubyClaude::Session
- Defined in:
- lib/ruby_claude/session.rb
Overview
A multi-turn conversation.
The first #query captures the session_id from the reply; subsequent queries transparently pass –resume <id> so the conversation continues.
Instance Attribute Summary collapse
-
#id ⇒ String?
readonly
The session id being resumed (nil until the first reply, unless one was supplied to Client#session).
Instance Method Summary collapse
-
#initialize(client, id: nil) ⇒ Session
constructor
A new instance of Session.
-
#query(prompt) ⇒ Response
(also: #ask)
Ask a question within this conversation, resuming the captured session.
Constructor Details
#initialize(client, id: nil) ⇒ Session
Returns a new instance of Session.
15 16 17 18 19 |
# File 'lib/ruby_claude/session.rb', line 15 def initialize(client, id: nil) @client = client @id = id @mutex = Mutex.new end |
Instance Attribute Details
#id ⇒ String? (readonly)
Returns the session id being resumed (nil until the first reply, unless one was supplied to Client#session).
11 12 13 |
# File 'lib/ruby_claude/session.rb', line 11 def id @id end |
Instance Method Details
#query(prompt) ⇒ Response Also known as: ask
Ask a question within this conversation, resuming the captured session.
25 26 27 28 29 30 31 |
# File 'lib/ruby_claude/session.rb', line 25 def query(prompt) @mutex.synchronize do response = @client.query(prompt, resume: @id) @id = response.session_id || @id response end end |