Class: Cadenya::Resources::MemoryLayers

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ MemoryLayers

Returns a new instance of MemoryLayers.



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

def initialize(core)
  @core = core
  @entries = MemoryEntries.new(core)
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



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

def entries
  @entries
end

Instance Method Details

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

Create a new memory layer



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

def create(metadata:, spec:, 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)}/memory_layers"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_MemoryLayerSpec(_v) }).call(spec),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::MemoryLayer.from_json(_data)
end

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

Delete a memory layer



60
61
62
63
64
65
# File 'lib/cadenya/resources/memory_layers.rb', line 60

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)}/memory_layers/#{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, type: nil, agent_id: nil, episodic_key_prefix: nil, labels: nil, sort_order: nil, include_info: nil, request_options: nil) ⇒ Object

List memory layers



16
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/memory_layers.rb', line 16

def list(workspace_id: nil, limit: nil, cursor: nil, prefix: nil, query: nil, type: nil, agent_id: nil, episodic_key_prefix: 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)}/memory_layers"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "prefix" => prefix,
    "query" => query,
    "type" => type,
    "agentId" => agent_id,
    "episodicKeyPrefix" => episodic_key_prefix,
    "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::MemoryLayer.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, type: type, agent_id: agent_id, episodic_key_prefix: episodic_key_prefix, labels: labels, sort_order: sort_order, include_info: include_info, request_options: request_options)
  end
end

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

Get a memory layer by ID



52
53
54
55
56
57
# File 'lib/cadenya/resources/memory_layers.rb', line 52

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)}/memory_layers/#{Util.path_param('id', id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::MemoryLayer.from_json(_data)
end

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

Update a memory layer



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cadenya/resources/memory_layers.rb', line 68

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)}/memory_layers/#{Util.path_param('id', id)}"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_MemoryLayerSpec(_v) }).call(spec),
    "updateMask" => update_mask,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:patch, _path, body: _body, request_options: request_options)
  Types::MemoryLayer.from_json(_data)
end