Class: RubyClaude::Session

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(client, id: nil) ⇒ Session

Returns a new instance of Session.

Parameters:

  • client (Client)

    the client used to run each turn

  • id (String, nil) (defaults to: nil)

    an existing session id to resume from the start



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

#idString? (readonly)

Returns the session id being resumed (nil until the first reply, unless one was supplied to Client#session).

Returns:

  • (String, nil)

    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.

Parameters:

  • prompt (String)

Returns:



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