Class: Exa::Services::AgentRunDelete

Inherits:
Object
  • Object
show all
Defined in:
lib/exa/services/agent_run_delete.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, run_id:) ⇒ AgentRunDelete

Returns a new instance of AgentRunDelete.



8
9
10
11
# File 'lib/exa/services/agent_run_delete.rb', line 8

def initialize(connection, run_id:)
  @connection = connection
  @run_id = run_id
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exa/services/agent_run_delete.rb', line 13

def call
  response = @connection.delete("/agent/runs/#{@run_id}")
  body = response.body

  # ponytail: 204-vs-200 unconfirmed; nil-guarded. Confirm against live API.
  if body.nil? || body.empty?
    return Resources::AgentRun.new(id: @run_id, object: "agent_run", status: "deleted")
  end

  Resources::AgentRun.new(
    id: body["id"],
    object: body["object"],
    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