Class: Cadenya::Resources::Agents

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenya/resources/agents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ Agents

Returns a new instance of Agents.



10
11
12
13
14
# File 'lib/cadenya/resources/agents.rb', line 10

def initialize(core)
  @core = core
  @schedules = AgentSchedules.new(core)
  @variations = AgentVariations.new(core)
end

Instance Attribute Details

#schedulesObject (readonly)

Returns the value of attribute schedules.



8
9
10
# File 'lib/cadenya/resources/agents.rb', line 8

def schedules
  @schedules
end

#variationsObject (readonly)

Returns the value of attribute variations.



8
9
10
# File 'lib/cadenya/resources/agents.rb', line 8

def variations
  @variations
end

Instance Method Details

#archive(id, workspace_id: nil, request_options: nil) ⇒ Object

Archive an agent



124
125
126
127
128
129
# File 'lib/cadenya/resources/agents.rb', line 124

def archive(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}:archive"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::Agent.from_json(_data)
end

#create(metadata:, spec:, workspace_id: nil, default_variation: nil, request_options: nil) ⇒ Object

Create a new agent



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cadenya/resources/agents.rb', line 40

def create(metadata:, spec:, workspace_id: nil, default_variation: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_AgentSpec(_v) }).call(spec),
    "defaultVariation" => default_variation.nil? ? nil : (->(_v) { Types.encode_CreateAgentVariationRequest(_v) }).call(default_variation),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::Agent.from_json(_data)
end

#delete(id, workspace_id: nil, request_options: nil) ⇒ Object

Delete an agent



103
104
105
106
107
108
# File 'lib/cadenya/resources/agents.rb', line 103

def delete(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}"
  @core.request(:delete, _path, expects_body: false, request_options: request_options)
  nil
end

#list(workspace_id: nil, limit: nil, cursor: nil, prefix: nil, query: nil, state: nil, variation_selection_mode: nil, labels: nil, sort_order: nil, include_info: nil, request_options: nil) ⇒ Object

List agents



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cadenya/resources/agents.rb', line 17

def list(workspace_id: nil, limit: nil, cursor: nil, prefix: nil, query: nil, state: nil, variation_selection_mode: nil, labels: nil, sort_order: nil, include_info: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "prefix" => prefix,
    "query" => query,
    "state" => state,
    "variationSelectionMode" => variation_selection_mode,
    "labels" => labels,
    "sortOrder" => sort_order,
    "includeInfo" => include_info,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::Agent.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list(workspace_id: workspace_id, limit: limit, cursor: _c, prefix: prefix, query: query, state: state, variation_selection_mode: variation_selection_mode, labels: labels, sort_order: sort_order, include_info: include_info, request_options: request_options)
  end
end

#list_feedback(agent_id, workspace_id: nil, limit: nil, cursor: nil, query: nil, sentiment: nil, agent_variation_id: nil, created_after: nil, created_before: nil, labels: nil, include_info: nil, request_options: nil) ⇒ Object

List feedback for an agent



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cadenya/resources/agents.rb', line 53

def list_feedback(agent_id, workspace_id: nil, limit: nil, cursor: nil, query: nil, sentiment: nil, agent_variation_id: nil, created_after: nil, created_before: nil, labels: nil, include_info: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('agentId', agent_id)}/feedback"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "query" => query,
    "sentiment" => sentiment,
    "agentVariationId" => agent_variation_id,
    "createdAfter" => created_after,
    "createdBefore" => created_before,
    "labels" => labels,
    "includeInfo" => include_info,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::ObjectiveFeedback.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_feedback(agent_id, workspace_id: workspace_id, limit: limit, cursor: _c, query: query, sentiment: sentiment, agent_variation_id: agent_variation_id, created_after: created_after, created_before: created_before, labels: labels, include_info: include_info, request_options: request_options)
  end
end

#list_webhook_deliveries(agent_id, workspace_id: nil, cursor: nil, limit: nil, objective_id: nil, event_type: nil, labels: nil, request_options: nil) ⇒ Object

List webhook deliveries



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cadenya/resources/agents.rb', line 76

def list_webhook_deliveries(agent_id, workspace_id: nil, cursor: nil, limit: nil, objective_id: nil, event_type: nil, labels: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('agentId', agent_id)}/webhook_deliveries"
  _query = {
    "cursor" => cursor,
    "limit" => limit,
    "objectiveId" => objective_id,
    "eventType" => event_type,
    "labels" => labels,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::WebhookDelivery.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list_webhook_deliveries(agent_id, workspace_id: workspace_id, cursor: _c, limit: limit, objective_id: objective_id, event_type: event_type, labels: labels, request_options: request_options)
  end
end

#publish(id, workspace_id: nil, request_options: nil) ⇒ Object

Publish an agent



132
133
134
135
136
137
# File 'lib/cadenya/resources/agents.rb', line 132

def publish(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}:publish"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::Agent.from_json(_data)
end

#retrieve(id, workspace_id: nil, request_options: nil) ⇒ Object

Get an agent by ID



95
96
97
98
99
100
# File 'lib/cadenya/resources/agents.rb', line 95

def retrieve(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::Agent.from_json(_data)
end

#unarchive(id, workspace_id: nil, request_options: nil) ⇒ Object

Unarchive an agent



140
141
142
143
144
145
# File 'lib/cadenya/resources/agents.rb', line 140

def unarchive(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}:unarchive"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::Agent.from_json(_data)
end

#unpublish(id, workspace_id: nil, request_options: nil) ⇒ Object

Unpublish an agent



148
149
150
151
152
153
# File 'lib/cadenya/resources/agents.rb', line 148

def unpublish(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}:unpublish"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::Agent.from_json(_data)
end

#update(id, workspace_id: nil, metadata: nil, spec: nil, update_mask: nil, request_options: nil) ⇒ Object

Update an agent



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cadenya/resources/agents.rb', line 111

def update(id, workspace_id: nil, metadata: nil, spec: nil, update_mask: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/agents/#{Util.path_param('id', id)}"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_AgentSpec(_v) }).call(spec),
    "updateMask" => update_mask,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:patch, _path, body: _body, request_options: request_options)
  Types::Agent.from_json(_data)
end