Module: HermesAgent::Client::Entities::SessionHeaders

Included in:
ChatCompletion, Response
Defined in:
lib/hermes_agent/client/entities/session_headers.rb

Overview

Mixin for entities that carry the server's session-continuity headers (X-Hermes-Session-ID / X-Hermes-Session-Key) alongside their JSON body. Included by the entities returned from endpoints that surface those headers (ChatCompletion, Response).

The session values come from response headers, not the JSON body, so they are stored separately from the wrapped payload: HermesAgent::Client::Entity#to_h and HermesAgent::Client::Entity#[] continue to reflect only the body. They do, however, participate in equality (#== / #eql?) and #hash, so two entities with the same body but different sessions are not equal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#session_idString? (readonly)

The session id from the response's X-Hermes-Session-ID header. The server always returns one (generating a fresh id when the request did not supply a session), except where the endpoint omits the header entirely (e.g. retrieving a response by id), in which case it is nil.

Returns:

  • (String, nil)


45
46
47
# File 'lib/hermes_agent/client/entities/session_headers.rb', line 45

def session_id
  @session_id
end

#session_keyString? (readonly)

The session key from the response's X-Hermes-Session-Key header. Present only when a session key was supplied on the request; otherwise nil.

Returns:

  • (String, nil)


53
54
55
# File 'lib/hermes_agent/client/entities/session_headers.rb', line 53

def session_key
  @session_key
end

Instance Method Details

#==(other) ⇒ boolean

Whether this entity equals another: same class, equal body payload, and equal session id/key.

Parameters:

  • other (Object)

    The object to compare against.

Returns:

  • (boolean)


62
63
64
# File 'lib/hermes_agent/client/entities/session_headers.rb', line 62

def ==(other)
  super && other.session_id == @session_id && other.session_key == @session_key
end

#hashInteger

A hash code consistent with #== and #eql?, incorporating the session values.

Returns:

  • (Integer)


72
73
74
# File 'lib/hermes_agent/client/entities/session_headers.rb', line 72

def hash
  [super, @session_id, @session_key].hash
end