Class: LanggraphPlatform::Resources::Threads

Inherits:
BaseResource show all
Defined in:
lib/langgraph_platform/resources/threads.rb

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from LanggraphPlatform::Resources::BaseResource

Instance Method Details

#copy(thread_id) ⇒ Object



57
58
59
60
# File 'lib/langgraph_platform/resources/threads.rb', line 57

def copy(thread_id)
  response = @client.post("/threads/#{thread_id}/copy")
  Models::Thread.new(response)
end

#create(**params) ⇒ Object



4
5
6
7
8
9
# File 'lib/langgraph_platform/resources/threads.rb', line 4

def create(**params)
  params[:metadata] ||= {}
  body = compact_params(params)
  response = @client.post('/threads', body)
  Models::Thread.new(response)
end

#delete(thread_id) ⇒ Object

rubocop:disable Naming/PredicateMethod



23
24
25
26
# File 'lib/langgraph_platform/resources/threads.rb', line 23

def delete(thread_id) # rubocop:disable Naming/PredicateMethod
  @client.delete("/threads/#{thread_id}")
  true
end

#find(thread_id) ⇒ Object



11
12
13
14
# File 'lib/langgraph_platform/resources/threads.rb', line 11

def find(thread_id)
  response = @client.get("/threads/#{thread_id}")
  Models::Thread.new(response)
end

#history(thread_id, **params) ⇒ Object



50
51
52
53
54
55
# File 'lib/langgraph_platform/resources/threads.rb', line 50

def history(thread_id, **params)
  params[:limit] ||= 10
  query_params = compact_params(params)
  response = @client.get("/threads/#{thread_id}/history", query_params)
  response.map { |state_data| Models::ThreadState.new(state_data) }
end

#search(**params) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/langgraph_platform/resources/threads.rb', line 28

def search(**params)
  params[:metadata] ||= {}
  params[:values] ||= {}
  params[:limit] ||= 10
  params[:offset] ||= 0
  body = compact_params(params)
  response = @client.post('/threads/search', body)
  response.map { |thread_data| Models::Thread.new(thread_data) }
end

#state(thread_id, **params) ⇒ Object



38
39
40
41
42
43
# File 'lib/langgraph_platform/resources/threads.rb', line 38

def state(thread_id, **params)
  params[:subgraphs] ||= false
  query_params = compact_params(params)
  response = @client.get("/threads/#{thread_id}/state", query_params)
  Models::ThreadState.new(response)
end

#update(thread_id, **params) ⇒ Object



16
17
18
19
20
21
# File 'lib/langgraph_platform/resources/threads.rb', line 16

def update(thread_id, **params)
  params[:metadata] ||= {}
  body = compact_params(params)
  response = @client.patch("/threads/#{thread_id}", body)
  Models::Thread.new(response)
end

#update_state(thread_id, **params) ⇒ Object



45
46
47
48
# File 'lib/langgraph_platform/resources/threads.rb', line 45

def update_state(thread_id, **params)
  body = compact_params(params)
  @client.post("/threads/#{thread_id}/state", body)
end