Class: LiveKit::AgentDispatchServiceClient

Inherits:
Twirp::Client
  • Object
show all
Includes:
AuthMixin
Defined in:
lib/livekit/agent_dispatch_service_client.rb

Overview

Client for LiveKit’s Agent Dispatch Service, which manages agent assignments to rooms This client handles creating, deleting, and retrieving agent dispatches

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthMixin

#auth_header

Constructor Details

#initialize(base_url, api_key: nil, api_secret: nil) ⇒ AgentDispatchServiceClient

Returns a new instance of AgentDispatchServiceClient.



13
14
15
16
17
# File 'lib/livekit/agent_dispatch_service_client.rb', line 13

def initialize(base_url, api_key: nil, api_secret: nil)
  super(File.join(Utils.to_http_url(base_url), "/twirp"))
  @api_key = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/livekit/agent_dispatch_service_client.rb', line 11

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



11
12
13
# File 'lib/livekit/agent_dispatch_service_client.rb', line 11

def api_secret
  @api_secret
end

Instance Method Details

#create_dispatch(room_name, agent_name, metadata: nil) ⇒ LiveKit::Proto::AgentDispatch

Creates a new agent dispatch for a named agent

Parameters:

  • room_name (String)

    The room to dispatch the agent to

  • agent_name (String)

    The name of the agent to dispatch

  • metadata (String, nil) (defaults to: nil)

    Optional metadata to include with the dispatch

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/livekit/agent_dispatch_service_client.rb', line 24

def create_dispatch(
  # room to dispatch agent to
  room_name,
  # agent to dispatch
  agent_name,
  # optional, metadata to send along with the job
  metadata: nil
)
  request = Proto::CreateAgentDispatchRequest.new(
    room: room_name,
    agent_name: agent_name,
    metadata: ,
  )
  self.rpc(
    :CreateDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
end

#delete_dispatch(dispatch_id, room_name) ⇒ LiveKit::Proto::AgentDispatch

Deletes an existing agent dispatch

Parameters:

  • dispatch_id (String)

    The ID of the dispatch to delete

  • room_name (String)

    The room name associated with the dispatch

Returns:



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/livekit/agent_dispatch_service_client.rb', line 48

def delete_dispatch(dispatch_id, room_name)
  request = Proto::DeleteAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  self.rpc(
    :DeleteDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
end

#get_dispatch(dispatch_id, room_name) ⇒ LiveKit::Proto::AgentDispatch?

Retrieves a specific agent dispatch by ID

Parameters:

  • dispatch_id (String)

    The ID of the dispatch to retrieve

  • room_name (String)

    The room name associated with the dispatch

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/livekit/agent_dispatch_service_client.rb', line 64

def get_dispatch(dispatch_id, room_name)
  request = Proto::ListAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  res = self.rpc(
    :ListDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
  if res.agent_dispatches.size > 0
    return res.agent_dispatches[0]
  end
  nil
end

#list_dispatch(room_name) ⇒ Array<LiveKit::Proto::AgentDispatch>

Lists all agent dispatches for a specific room

Parameters:

  • room_name (String)

    The room name to list dispatches for

Returns:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/livekit/agent_dispatch_service_client.rb', line 83

def list_dispatch(room_name)
  request = Proto::ListAgentDispatchRequest.new(
    room: room_name,
  )
  res = self.rpc(
    :ListDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
  res.agent_dispatches
end