Class: Google::ADK::Session
- Inherits:
-
Object
- Object
- Google::ADK::Session
- Defined in:
- lib/google/adk/session.rb
Overview
Represents a conversation session
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#events ⇒ Object
Returns the value of attribute events.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
-
#state ⇒ Object
Returns the value of attribute state.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
-
.from_h(hash) ⇒ Session
Create session from hash.
Instance Method Summary collapse
-
#initialize(id:, app_name:, user_id:, state: {}, events: [], last_update_time: nil) ⇒ Session
constructor
Initialize a session.
-
#to_h ⇒ Hash
Convert to hash representation.
Constructor Details
#initialize(id:, app_name:, user_id:, state: {}, events: [], last_update_time: nil) ⇒ Session
Initialize a session
20 21 22 23 24 25 26 27 |
# File 'lib/google/adk/session.rb', line 20 def initialize(id:, app_name:, user_id:, state: {}, events: [], last_update_time: nil) @id = id @app_name = app_name @user_id = user_id @state = state @events = events @last_update_time = last_update_time || Time.now end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def app_name @app_name end |
#events ⇒ Object
Returns the value of attribute events.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def events @events end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def id @id end |
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def last_update_time @last_update_time end |
#state ⇒ Object
Returns the value of attribute state.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def state @state end |
#user_id ⇒ Object
Returns the value of attribute user_id.
10 11 12 |
# File 'lib/google/adk/session.rb', line 10 def user_id @user_id end |
Class Method Details
.from_h(hash) ⇒ Session
Create session from hash
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/google/adk/session.rb', line 47 def self.from_h(hash) new( id: hash[:id], app_name: hash[:app_name], user_id: hash[:user_id], state: hash[:state] || {}, events: (hash[:events] || []).map { |e| Event.new(**e) }, last_update_time: Time.parse(hash[:last_update_time]) ) end |
Instance Method Details
#to_h ⇒ Hash
Convert to hash representation
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/google/adk/session.rb', line 32 def to_h { id: @id, app_name: @app_name, user_id: @user_id, state: @state, events: @events.map(&:to_h), last_update_time: @last_update_time.iso8601 } end |