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, #rpc!

Constructor Details

#initialize(base_url, api_key: nil, api_secret: nil, token: nil, failover: true, connection: nil) ⇒ AgentDispatchServiceClient

Returns a new instance of AgentDispatchServiceClient.



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

def initialize(base_url, api_key: nil, api_secret: nil, token: nil, failover: true, connection: nil)
  super(connection || LiveKit::Failover.connection(base_url, failover))
  @api_key = api_key
  @api_secret = api_secret
  @token = token
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



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

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:



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

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: ,
  )
  rpc!(
    :CreateDispatch,
    request,
    headers: auth_header(video_grant: 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:



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

def delete_dispatch(dispatch_id, room_name)
  request = Proto::DeleteAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  rpc!(
    :DeleteDispatch,
    request,
    headers: auth_header(video_grant: 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:



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

def get_dispatch(dispatch_id, room_name)
  request = Proto::ListAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  res = rpc!(
    :ListDispatch,
    request,
    headers: auth_header(video_grant: 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:



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

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