Class: Exa::Resources::AgentRun

Inherits:
Struct
  • Object
show all
Defined in:
lib/exa/resources/agent_run.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, object:, status:, stop_reason: nil, created_at: nil, completed_at: nil, request: nil, output: nil, usage: nil, cost_dollars: nil) ⇒ AgentRun

Returns a new instance of AgentRun.



7
8
9
10
# File 'lib/exa/resources/agent_run.rb', line 7

def initialize(id:, object:, status:, stop_reason: nil, created_at: nil, completed_at: nil, request: nil, output: nil, usage: nil, cost_dollars: nil)
  super
  freeze
end

Instance Attribute Details

#completed_atObject

Returns the value of attribute completed_at

Returns:

  • (Object)

    the current value of completed_at



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def completed_at
  @completed_at
end

#cost_dollarsObject

Returns the value of attribute cost_dollars

Returns:

  • (Object)

    the current value of cost_dollars



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def cost_dollars
  @cost_dollars
end

#created_atObject

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def created_at
  @created_at
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def id
  @id
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def object
  @object
end

#outputObject

Returns the value of attribute output

Returns:

  • (Object)

    the current value of output



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def output
  @output
end

#requestObject

Returns the value of attribute request

Returns:

  • (Object)

    the current value of request



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def request
  @request
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def status
  @status
end

#stop_reasonObject

Returns the value of attribute stop_reason

Returns:

  • (Object)

    the current value of stop_reason



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def stop_reason
  @stop_reason
end

#usageObject

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



3
4
5
# File 'lib/exa/resources/agent_run.rb', line 3

def usage
  @usage
end

Class Method Details

.from_response(body) ⇒ Object

Build from a raw API response body (camelCase keys), e.g. a GET payload or the data of a terminal agent_run.* stream event.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exa/resources/agent_run.rb', line 14

def self.from_response(body)
  new(
    id: body["id"],
    object: body["object"] || "agent_run",
    status: body["status"],
    stop_reason: body["stopReason"],
    created_at: body["createdAt"],
    completed_at: body["completedAt"],
    request: body["request"],
    output: body["output"],
    usage: body["usage"],
    cost_dollars: body["costDollars"]
  )
end

Instance Method Details

#cancelled?Boolean

Returns:

  • (Boolean)


33
# File 'lib/exa/resources/agent_run.rb', line 33

def cancelled? = status == 'cancelled'

#completed?Boolean

Returns:

  • (Boolean)


31
# File 'lib/exa/resources/agent_run.rb', line 31

def completed? = status == 'completed'

#failed?Boolean

Returns:

  • (Boolean)


32
# File 'lib/exa/resources/agent_run.rb', line 32

def failed?    = status == 'failed'

#finished?Boolean

Returns:

  • (Boolean)


35
# File 'lib/exa/resources/agent_run.rb', line 35

def finished? = completed? || failed? || cancelled?

#queued?Boolean

Returns:

  • (Boolean)


29
# File 'lib/exa/resources/agent_run.rb', line 29

def queued?    = status == 'queued'

#running?Boolean

Returns:

  • (Boolean)


30
# File 'lib/exa/resources/agent_run.rb', line 30

def running?   = status == 'running'

#to_hObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/exa/resources/agent_run.rb', line 37

def to_h
  result = {
    id: id,
    object: object,
    status: status
  }
  result[:stop_reason]  = stop_reason  if stop_reason
  result[:created_at]   = created_at   if created_at
  result[:completed_at] = completed_at if completed_at
  result[:request]      = request      if request
  result[:output]       = output       if output
  result[:usage]        = usage        if usage
  result[:cost_dollars] = cost_dollars if cost_dollars
  result
end