elevenlabs_client 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +144 -0
- data/README.md +163 -64
- data/lib/elevenlabs_client/client.rb +110 -272
- data/lib/elevenlabs_client/configuration.rb +119 -0
- data/lib/elevenlabs_client/endpoints/admin/pronunciation_dictionaries.rb +103 -0
- data/lib/elevenlabs_client/endpoints/admin/service_account_api_keys.rb +77 -0
- data/lib/elevenlabs_client/endpoints/admin/user.rb +12 -0
- data/lib/elevenlabs_client/endpoints/admin/workspace_groups.rb +56 -0
- data/lib/elevenlabs_client/endpoints/admin/workspace_invites.rb +52 -0
- data/lib/elevenlabs_client/endpoints/admin/workspace_members.rb +31 -0
- data/lib/elevenlabs_client/endpoints/admin/workspace_resources.rb +53 -0
- data/lib/elevenlabs_client/endpoints/admin/workspace_webhooks.rb +30 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/agents.rb +165 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/batch_calling.rb +89 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/conversations.rb +121 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/knowledge_base.rb +234 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/llm_usage.rb +50 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/mcp_servers.rb +139 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/outbound_calling.rb +55 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/phone_numbers.rb +86 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/test_invocations.rb +44 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/tests.rb +138 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/tools.rb +107 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/widgets.rb +52 -0
- data/lib/elevenlabs_client/endpoints/agents_platform/workspace.rb +130 -0
- data/lib/elevenlabs_client/errors.rb +4 -0
- data/lib/elevenlabs_client/http_client.rb +325 -0
- data/lib/elevenlabs_client/version.rb +1 -1
- data/lib/elevenlabs_client.rb +88 -7
- metadata +24 -2
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElevenlabsClient
|
4
|
+
module Endpoints
|
5
|
+
module AgentsPlatform
|
6
|
+
class Conversations
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /v1/convai/conversations
|
12
|
+
# Get all conversations of agents that user owns
|
13
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/list
|
14
|
+
#
|
15
|
+
# @param options [Hash] Query parameters
|
16
|
+
# @option options [String] :cursor Used for fetching next page
|
17
|
+
# @option options [String] :agent_id The id of the agent to filter by
|
18
|
+
# @option options [String] :call_successful The result of the success evaluation ("success", "failure", "unknown")
|
19
|
+
# @option options [Integer] :call_start_before_unix Unix timestamp to filter conversations up to this start date
|
20
|
+
# @option options [Integer] :call_start_after_unix Unix timestamp to filter conversations after this start date
|
21
|
+
# @option options [String] :user_id Filter conversations by the user ID who initiated them
|
22
|
+
# @option options [Integer] :page_size How many conversations to return at maximum (1-100, default: 30)
|
23
|
+
# @option options [String] :summary_mode Whether to include transcript summaries ("exclude", "include", default: "exclude")
|
24
|
+
# @return [Hash] List of conversations with pagination info
|
25
|
+
def list(**options)
|
26
|
+
endpoint = "/v1/convai/conversations"
|
27
|
+
query_params = options.compact
|
28
|
+
|
29
|
+
if query_params.any?
|
30
|
+
query_string = URI.encode_www_form(query_params)
|
31
|
+
endpoint = "#{endpoint}?#{query_string}"
|
32
|
+
end
|
33
|
+
|
34
|
+
@client.get(endpoint)
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET /v1/convai/conversations/{conversation_id}
|
38
|
+
# Get the details of a particular conversation
|
39
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/get
|
40
|
+
#
|
41
|
+
# @param conversation_id [String] The id of the conversation
|
42
|
+
# @return [Hash] Conversation details including transcript and metadata
|
43
|
+
def get(conversation_id)
|
44
|
+
endpoint = "/v1/convai/conversations/#{conversation_id}"
|
45
|
+
@client.get(endpoint)
|
46
|
+
end
|
47
|
+
|
48
|
+
# DELETE /v1/convai/conversations/{conversation_id}
|
49
|
+
# Delete a particular conversation
|
50
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/delete
|
51
|
+
#
|
52
|
+
# @param conversation_id [String] The id of the conversation
|
53
|
+
# @return [Hash] Empty response on success
|
54
|
+
def delete(conversation_id)
|
55
|
+
endpoint = "/v1/convai/conversations/#{conversation_id}"
|
56
|
+
@client.delete(endpoint)
|
57
|
+
end
|
58
|
+
|
59
|
+
# GET /v1/convai/conversations/{conversation_id}/audio
|
60
|
+
# Get the audio recording of a particular conversation
|
61
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/audio
|
62
|
+
#
|
63
|
+
# @param conversation_id [String] The id of the conversation
|
64
|
+
# @return [String] Binary audio data
|
65
|
+
def get_audio(conversation_id)
|
66
|
+
endpoint = "/v1/convai/conversations/#{conversation_id}/audio"
|
67
|
+
@client.get_binary(endpoint)
|
68
|
+
end
|
69
|
+
|
70
|
+
# GET /v1/convai/conversation/get-signed-url
|
71
|
+
# Get a signed url to start a conversation with an agent that requires authorization
|
72
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/get-signed-url
|
73
|
+
#
|
74
|
+
# @param agent_id [String] The id of the agent
|
75
|
+
# @param options [Hash] Optional parameters
|
76
|
+
# @option options [Boolean] :include_conversation_id Whether to include a conversation_id with the response (default: false)
|
77
|
+
# @return [Hash] Response containing signed_url
|
78
|
+
def get_signed_url(agent_id, **options)
|
79
|
+
endpoint = "/v1/convai/conversation/get-signed-url"
|
80
|
+
query_params = { agent_id: agent_id }.merge(options.compact)
|
81
|
+
|
82
|
+
query_string = URI.encode_www_form(query_params)
|
83
|
+
endpoint_with_query = "#{endpoint}?#{query_string}"
|
84
|
+
|
85
|
+
@client.get(endpoint_with_query)
|
86
|
+
end
|
87
|
+
|
88
|
+
# GET /v1/convai/conversation/token
|
89
|
+
# Get a WebRTC session token for real-time communication
|
90
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/token
|
91
|
+
#
|
92
|
+
# @param agent_id [String] The id of the agent
|
93
|
+
# @param options [Hash] Optional parameters
|
94
|
+
# @option options [String] :participant_name Optional custom participant name
|
95
|
+
# @return [Hash] Response containing WebRTC token
|
96
|
+
def get_token(agent_id, **options)
|
97
|
+
endpoint = "/v1/convai/conversation/token"
|
98
|
+
query_params = { agent_id: agent_id }.merge(options.compact)
|
99
|
+
|
100
|
+
query_string = URI.encode_www_form(query_params)
|
101
|
+
endpoint_with_query = "#{endpoint}?#{query_string}"
|
102
|
+
|
103
|
+
@client.get(endpoint_with_query)
|
104
|
+
end
|
105
|
+
|
106
|
+
# POST /v1/convai/conversations/{conversation_id}/feedback
|
107
|
+
# Send the feedback for the given conversation
|
108
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/conversations/feedback
|
109
|
+
#
|
110
|
+
# @param conversation_id [String] The id of the conversation
|
111
|
+
# @param feedback [String] Either 'like' or 'dislike' to indicate the feedback
|
112
|
+
# @return [Hash] Empty response on success
|
113
|
+
def send_feedback(conversation_id, feedback)
|
114
|
+
endpoint = "/v1/convai/conversations/#{conversation_id}/feedback"
|
115
|
+
request_body = { feedback: feedback }
|
116
|
+
@client.post(endpoint, request_body)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElevenlabsClient
|
4
|
+
module Endpoints
|
5
|
+
module AgentsPlatform
|
6
|
+
class KnowledgeBase
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /v1/convai/knowledge-base
|
12
|
+
# Get a list of available knowledge base documents
|
13
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/list
|
14
|
+
#
|
15
|
+
# @param options [Hash] Query parameters
|
16
|
+
# @option options [Integer] :page_size How many documents to return at maximum (1-100, default: 30)
|
17
|
+
# @option options [String] :search Filter documents whose names start with this string
|
18
|
+
# @option options [Boolean] :show_only_owned_documents Return only documents owned by you (default: false)
|
19
|
+
# @option options [Array<String>] :types Filter by document types ("file", "url", "text")
|
20
|
+
# @option options [String] :sort_direction Sort direction ("asc" or "desc")
|
21
|
+
# @option options [String] :sort_by Sort field ("name", "created_at", "updated_at", "size")
|
22
|
+
# @option options [Boolean] :use_typesense Use typesense DB for search (deprecated, default: false)
|
23
|
+
# @option options [String] :cursor Used for fetching next page
|
24
|
+
# @return [Hash] List of knowledge base documents with pagination info
|
25
|
+
def list(**options)
|
26
|
+
endpoint = "/v1/convai/knowledge-base"
|
27
|
+
query_params = options.compact
|
28
|
+
|
29
|
+
if query_params.any?
|
30
|
+
query_string = URI.encode_www_form(query_params)
|
31
|
+
endpoint = "#{endpoint}?#{query_string}"
|
32
|
+
end
|
33
|
+
|
34
|
+
@client.get(endpoint)
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET /v1/convai/knowledge-base/{documentation_id}
|
38
|
+
# Get details about a specific documentation making up the agent's knowledge base
|
39
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get
|
40
|
+
#
|
41
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
42
|
+
# @param agent_id [String] Optional agent ID for context
|
43
|
+
# @return [Hash] Knowledge base document details
|
44
|
+
def get(documentation_id, agent_id: nil)
|
45
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
|
46
|
+
|
47
|
+
if agent_id
|
48
|
+
endpoint = "#{endpoint}?agent_id=#{agent_id}"
|
49
|
+
end
|
50
|
+
|
51
|
+
@client.get(endpoint)
|
52
|
+
end
|
53
|
+
|
54
|
+
# PATCH /v1/convai/knowledge-base/{documentation_id}
|
55
|
+
# Update the name of a document
|
56
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/update
|
57
|
+
#
|
58
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
59
|
+
# @param name [String] A custom, human-readable name for the document
|
60
|
+
# @return [Hash] Updated knowledge base document details
|
61
|
+
def update(documentation_id, name:)
|
62
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
|
63
|
+
request_body = { name: name }
|
64
|
+
@client.patch(endpoint, request_body)
|
65
|
+
end
|
66
|
+
|
67
|
+
# DELETE /v1/convai/knowledge-base/{documentation_id}
|
68
|
+
# Delete a document from the knowledge base
|
69
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/delete
|
70
|
+
#
|
71
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
72
|
+
# @param force [Boolean] Delete regardless of agent dependencies (default: false)
|
73
|
+
# @return [Hash] Empty response on success
|
74
|
+
def delete(documentation_id, force: false)
|
75
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}"
|
76
|
+
|
77
|
+
if force
|
78
|
+
endpoint = "#{endpoint}?force=true"
|
79
|
+
end
|
80
|
+
|
81
|
+
@client.delete(endpoint)
|
82
|
+
end
|
83
|
+
|
84
|
+
# POST /v1/convai/knowledge-base/url
|
85
|
+
# Create a knowledge base document generated by scraping the given webpage
|
86
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-url
|
87
|
+
#
|
88
|
+
# @param url [String] URL to a page of documentation
|
89
|
+
# @param name [String] Optional custom name for the document
|
90
|
+
# @return [Hash] Created document with ID and name
|
91
|
+
def create_from_url(url, name: nil)
|
92
|
+
endpoint = "/v1/convai/knowledge-base/url"
|
93
|
+
request_body = { url: url }
|
94
|
+
request_body[:name] = name if name
|
95
|
+
@client.post(endpoint, request_body)
|
96
|
+
end
|
97
|
+
|
98
|
+
# POST /v1/convai/knowledge-base/text
|
99
|
+
# Create a knowledge base document containing the provided text
|
100
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-text
|
101
|
+
#
|
102
|
+
# @param text [String] Text content to be added to the knowledge base
|
103
|
+
# @param name [String] Optional custom name for the document
|
104
|
+
# @return [Hash] Created document with ID and name
|
105
|
+
def create_from_text(text, name: nil)
|
106
|
+
endpoint = "/v1/convai/knowledge-base/text"
|
107
|
+
request_body = { text: text }
|
108
|
+
request_body[:name] = name if name
|
109
|
+
@client.post(endpoint, request_body)
|
110
|
+
end
|
111
|
+
|
112
|
+
# POST /v1/convai/knowledge-base/file
|
113
|
+
# Create a knowledge base document generated from the uploaded file
|
114
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/create-file
|
115
|
+
#
|
116
|
+
# @param file_io [IO] File IO object to upload
|
117
|
+
# @param filename [String] Original filename
|
118
|
+
# @param name [String] Optional custom name for the document
|
119
|
+
# @return [Hash] Created document with ID and name
|
120
|
+
def create_from_file(file_io:, filename:, name: nil)
|
121
|
+
endpoint = "/v1/convai/knowledge-base/file"
|
122
|
+
|
123
|
+
payload = {
|
124
|
+
"file" => @client.file_part(file_io, filename)
|
125
|
+
}
|
126
|
+
payload["name"] = name if name
|
127
|
+
|
128
|
+
@client.post_multipart(endpoint, payload)
|
129
|
+
end
|
130
|
+
|
131
|
+
# POST /v1/convai/knowledge-base/{documentation_id}/rag-index
|
132
|
+
# Trigger or get status of RAG indexing for a document
|
133
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/compute-rag-index
|
134
|
+
#
|
135
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
136
|
+
# @param model [String] RAG model to use ("e5_mistral_7b_instruct" or "multilingual_e5_large_instruct")
|
137
|
+
# @return [Hash] RAG index status and progress
|
138
|
+
def compute_rag_index(documentation_id, model:)
|
139
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index"
|
140
|
+
request_body = { model: model }
|
141
|
+
@client.post(endpoint, request_body)
|
142
|
+
end
|
143
|
+
|
144
|
+
# GET /v1/convai/knowledge-base/{documentation_id}/rag-index
|
145
|
+
# Get information about all RAG indexes of the specified document
|
146
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-rag-index
|
147
|
+
#
|
148
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
149
|
+
# @return [Hash] List of RAG indexes for the document
|
150
|
+
def get_rag_index(documentation_id)
|
151
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index"
|
152
|
+
@client.get(endpoint)
|
153
|
+
end
|
154
|
+
|
155
|
+
# DELETE /v1/convai/knowledge-base/{documentation_id}/rag-index/{rag_index_id}
|
156
|
+
# Delete RAG index for the knowledge base document
|
157
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/delete-rag-index
|
158
|
+
#
|
159
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
160
|
+
# @param rag_index_id [String] The id of RAG index of document
|
161
|
+
# @return [Hash] Deleted RAG index information
|
162
|
+
def delete_rag_index(documentation_id, rag_index_id)
|
163
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/rag-index/#{rag_index_id}"
|
164
|
+
@client.delete(endpoint)
|
165
|
+
end
|
166
|
+
|
167
|
+
# GET /v1/convai/knowledge-base/rag-index
|
168
|
+
# Get total size and other information of RAG indexes used by knowledge base documents
|
169
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-rag-index-overview
|
170
|
+
#
|
171
|
+
# @return [Hash] RAG index overview with usage statistics
|
172
|
+
def get_rag_index_overview
|
173
|
+
endpoint = "/v1/convai/knowledge-base/rag-index"
|
174
|
+
@client.get(endpoint)
|
175
|
+
end
|
176
|
+
|
177
|
+
# GET /v1/convai/knowledge-base/{documentation_id}/dependent-agents
|
178
|
+
# Get a list of agents depending on this knowledge base document
|
179
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-dependent-agents
|
180
|
+
#
|
181
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
182
|
+
# @param options [Hash] Query parameters
|
183
|
+
# @option options [String] :cursor Used for fetching next page
|
184
|
+
# @option options [Integer] :page_size How many agents to return at maximum (1-100, default: 30)
|
185
|
+
# @return [Hash] List of dependent agents with pagination info
|
186
|
+
def get_dependent_agents(documentation_id, **options)
|
187
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/dependent-agents"
|
188
|
+
query_params = options.compact
|
189
|
+
|
190
|
+
if query_params.any?
|
191
|
+
query_string = URI.encode_www_form(query_params)
|
192
|
+
endpoint = "#{endpoint}?#{query_string}"
|
193
|
+
end
|
194
|
+
|
195
|
+
@client.get(endpoint)
|
196
|
+
end
|
197
|
+
|
198
|
+
# GET /v1/convai/knowledge-base/{documentation_id}/content
|
199
|
+
# Get the entire content of a document from the knowledge base
|
200
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-content
|
201
|
+
#
|
202
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
203
|
+
# @return [String] Streaming document content
|
204
|
+
def get_content(documentation_id)
|
205
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/content"
|
206
|
+
@client.get(endpoint)
|
207
|
+
end
|
208
|
+
|
209
|
+
# GET /v1/convai/knowledge-base/{documentation_id}/chunk/{chunk_id}
|
210
|
+
# Get details about a specific documentation part used by RAG
|
211
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-chunk
|
212
|
+
#
|
213
|
+
# @param documentation_id [String] The id of a document from the knowledge base
|
214
|
+
# @param chunk_id [String] The id of a document RAG chunk
|
215
|
+
# @return [Hash] Chunk details with ID, name, and content
|
216
|
+
def get_chunk(documentation_id, chunk_id)
|
217
|
+
endpoint = "/v1/convai/knowledge-base/#{documentation_id}/chunk/#{chunk_id}"
|
218
|
+
@client.get(endpoint)
|
219
|
+
end
|
220
|
+
|
221
|
+
# GET /v1/convai/agent/{agent_id}/knowledge-base/size
|
222
|
+
# Returns the number of pages in the agent's knowledge base
|
223
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/knowledge-base/get-size
|
224
|
+
#
|
225
|
+
# @param agent_id [String] The agent ID
|
226
|
+
# @return [Hash] Knowledge base size information
|
227
|
+
def get_agent_knowledge_base_size(agent_id)
|
228
|
+
endpoint = "/v1/convai/agent/#{agent_id}/knowledge-base/size"
|
229
|
+
@client.get(endpoint)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElevenlabsClient
|
4
|
+
module Endpoints
|
5
|
+
module AgentsPlatform
|
6
|
+
# LLM Usage endpoint - refactored for better maintainability
|
7
|
+
class LlmUsage
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# POST /v1/convai/llm-usage/calculate
|
13
|
+
# Returns a list of LLM models and the expected cost for using them based on the provided values
|
14
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/llm-usage/calculate
|
15
|
+
#
|
16
|
+
# @param prompt_length [Integer] Length of the prompt in characters (required)
|
17
|
+
# @param number_of_pages [Integer] Pages of content in PDF documents or URLs in the agent's knowledge base (required)
|
18
|
+
# @param rag_enabled [Boolean] Whether RAG is enabled (required)
|
19
|
+
# @return [Hash] JSON response containing list of LLM models with pricing information
|
20
|
+
def calculate(prompt_length:, number_of_pages:, rag_enabled:)
|
21
|
+
validate_required!(:prompt_length, prompt_length)
|
22
|
+
validate_required!(:number_of_pages, number_of_pages)
|
23
|
+
validate_required!(:rag_enabled, rag_enabled)
|
24
|
+
|
25
|
+
body = {
|
26
|
+
prompt_length: prompt_length,
|
27
|
+
number_of_pages: number_of_pages,
|
28
|
+
rag_enabled: rag_enabled
|
29
|
+
}
|
30
|
+
|
31
|
+
@client.post("/v1/convai/llm-usage/calculate", body)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convenience alias
|
35
|
+
alias_method :calculate_usage, :calculate
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :client
|
40
|
+
|
41
|
+
# Parameter validation that handles boolean values properly
|
42
|
+
def validate_required!(param_name, value)
|
43
|
+
if value.nil?
|
44
|
+
raise ArgumentError, "#{param_name} is required"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElevenlabsClient
|
4
|
+
module Endpoints
|
5
|
+
module AgentsPlatform
|
6
|
+
# MCP Servers endpoint - refactored for better maintainability
|
7
|
+
class McpServers
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# POST /v1/convai/mcp-servers
|
13
|
+
# Create a new MCP server configuration in the workspace
|
14
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/create
|
15
|
+
#
|
16
|
+
# @param config [Hash] Configuration details for the MCP Server (required)
|
17
|
+
# @option config [String] :url MCP server URL
|
18
|
+
# @option config [String] :name MCP server name
|
19
|
+
# @option config [String] :approval_policy Approval policy ("auto_approve_all", "require_approval_all", "require_approval_per_tool")
|
20
|
+
# @option config [Array] :tool_approval_hashes Tool approval configurations
|
21
|
+
# @option config [String] :transport Transport method (default: "SSE")
|
22
|
+
# @option config [Hash] :secret_token Secret token configuration
|
23
|
+
# @option config [Hash] :request_headers Request headers
|
24
|
+
# @option config [String] :description MCP server description
|
25
|
+
# @return [Hash] JSON response containing created MCP server details
|
26
|
+
def create(config:)
|
27
|
+
validate_required!(:config, config)
|
28
|
+
raise ArgumentError, "config cannot be empty" if config.empty?
|
29
|
+
|
30
|
+
body = { config: config }
|
31
|
+
|
32
|
+
@client.post("/v1/convai/mcp-servers", body)
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /v1/convai/mcp-servers
|
36
|
+
# Retrieve all MCP server configurations available in the workspace
|
37
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/list
|
38
|
+
#
|
39
|
+
# @return [Hash] JSON response containing list of MCP servers
|
40
|
+
def list
|
41
|
+
@client.get("/v1/convai/mcp-servers")
|
42
|
+
end
|
43
|
+
|
44
|
+
# GET /v1/convai/mcp-servers/:mcp_server_id
|
45
|
+
# Retrieve a specific MCP server configuration from the workspace
|
46
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/get
|
47
|
+
#
|
48
|
+
# @param mcp_server_id [String] ID of the MCP Server (required)
|
49
|
+
# @return [Hash] JSON response containing MCP server details
|
50
|
+
def get(mcp_server_id)
|
51
|
+
validate_required!(:mcp_server_id, mcp_server_id)
|
52
|
+
|
53
|
+
@client.get("/v1/convai/mcp-servers/#{mcp_server_id}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# PATCH /v1/convai/mcp-servers/:mcp_server_id/approval-policy
|
57
|
+
# Update the approval policy configuration for an MCP server
|
58
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/update-approval-policy
|
59
|
+
#
|
60
|
+
# @param mcp_server_id [String] ID of the MCP Server (required)
|
61
|
+
# @param approval_policy [String] The approval mode to set for the MCP server (required)
|
62
|
+
# - "auto_approve_all": Automatically approve all tools
|
63
|
+
# - "require_approval_all": Require approval for all tools
|
64
|
+
# - "require_approval_per_tool": Require approval per individual tool
|
65
|
+
# @return [Hash] JSON response containing updated MCP server details
|
66
|
+
def update_approval_policy(mcp_server_id, approval_policy:)
|
67
|
+
validate_required!(:mcp_server_id, mcp_server_id)
|
68
|
+
validate_required!(:approval_policy, approval_policy)
|
69
|
+
|
70
|
+
valid_policies = %w[auto_approve_all require_approval_all require_approval_per_tool]
|
71
|
+
unless valid_policies.include?(approval_policy.to_s)
|
72
|
+
raise ArgumentError, "approval_policy must be one of: #{valid_policies.join(', ')}"
|
73
|
+
end
|
74
|
+
|
75
|
+
body = { approval_policy: approval_policy }
|
76
|
+
|
77
|
+
@client.patch("/v1/convai/mcp-servers/#{mcp_server_id}/approval-policy", body)
|
78
|
+
end
|
79
|
+
|
80
|
+
# POST /v1/convai/mcp-servers/:mcp_server_id/tool-approvals
|
81
|
+
# Add approval for a specific MCP tool when using per-tool approval mode
|
82
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/create-tool-approval
|
83
|
+
#
|
84
|
+
# @param mcp_server_id [String] ID of the MCP Server (required)
|
85
|
+
# @param tool_name [String] The name of the MCP tool (required)
|
86
|
+
# @param tool_description [String] The description of the MCP tool (required)
|
87
|
+
# @param options [Hash] Optional parameters
|
88
|
+
# @option options [Hash] :input_schema The input schema of the MCP tool
|
89
|
+
# @option options [String] :approval_policy Tool-level approval policy ("auto_approved", "requires_approval")
|
90
|
+
# @return [Hash] JSON response containing updated MCP server details
|
91
|
+
def create_tool_approval(mcp_server_id, tool_name:, tool_description:, **options)
|
92
|
+
validate_required!(:mcp_server_id, mcp_server_id)
|
93
|
+
validate_required!(:tool_name, tool_name)
|
94
|
+
validate_required!(:tool_description, tool_description)
|
95
|
+
|
96
|
+
body = {
|
97
|
+
tool_name: tool_name,
|
98
|
+
tool_description: tool_description
|
99
|
+
}.merge(options.compact)
|
100
|
+
|
101
|
+
@client.post("/v1/convai/mcp-servers/#{mcp_server_id}/tool-approvals", body)
|
102
|
+
end
|
103
|
+
|
104
|
+
# DELETE /v1/convai/mcp-servers/:mcp_server_id/tool-approvals/:tool_name
|
105
|
+
# Remove approval for a specific MCP tool when using per-tool approval mode
|
106
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/mcp-servers/delete-tool-approval
|
107
|
+
#
|
108
|
+
# @param mcp_server_id [String] ID of the MCP Server (required)
|
109
|
+
# @param tool_name [String] Name of the MCP tool to remove approval for (required)
|
110
|
+
# @return [Hash] JSON response containing updated MCP server details
|
111
|
+
def delete_tool_approval(mcp_server_id, tool_name)
|
112
|
+
validate_required!(:mcp_server_id, mcp_server_id)
|
113
|
+
validate_required!(:tool_name, tool_name)
|
114
|
+
|
115
|
+
@client.delete("/v1/convai/mcp-servers/#{mcp_server_id}/tool-approvals/#{tool_name}")
|
116
|
+
end
|
117
|
+
|
118
|
+
# Convenience method aliases
|
119
|
+
alias_method :servers, :list
|
120
|
+
alias_method :get_server, :get
|
121
|
+
alias_method :update_policy, :update_approval_policy
|
122
|
+
alias_method :approve_tool, :create_tool_approval
|
123
|
+
alias_method :remove_tool_approval, :delete_tool_approval
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
attr_reader :client
|
128
|
+
|
129
|
+
# Parameter validation
|
130
|
+
def validate_required!(param_name, value)
|
131
|
+
if value.nil? || (value.respond_to?(:empty?) && value.empty?) ||
|
132
|
+
(value.is_a?(String) && value.strip.empty?)
|
133
|
+
raise ArgumentError, "#{param_name} is required"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ElevenlabsClient
|
4
|
+
module Endpoints
|
5
|
+
module AgentsPlatform
|
6
|
+
class OutboundCalling
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
# POST /v1/convai/sip-trunk/outbound-call
|
12
|
+
# Handle an outbound call via SIP trunk
|
13
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/sip-trunk/outbound-call
|
14
|
+
#
|
15
|
+
# @param agent_id [String] The agent ID to use for the call
|
16
|
+
# @param agent_phone_number_id [String] The phone number ID to call from
|
17
|
+
# @param to_number [String] The phone number to call
|
18
|
+
# @param options [Hash] Optional parameters
|
19
|
+
# @option options [Hash] :conversation_initiation_client_data Additional data for conversation initiation
|
20
|
+
# @return [Hash] JSON response containing success status, message, conversation_id, and sip_call_id
|
21
|
+
def sip_trunk_call(agent_id:, agent_phone_number_id:, to_number:, **options)
|
22
|
+
endpoint = "/v1/convai/sip-trunk/outbound-call"
|
23
|
+
request_body = {
|
24
|
+
agent_id: agent_id,
|
25
|
+
agent_phone_number_id: agent_phone_number_id,
|
26
|
+
to_number: to_number
|
27
|
+
}.merge(options)
|
28
|
+
|
29
|
+
@client.post(endpoint, request_body)
|
30
|
+
end
|
31
|
+
|
32
|
+
# POST /v1/convai/twilio/outbound-call
|
33
|
+
# Handle an outbound call via Twilio
|
34
|
+
# Documentation: https://elevenlabs.io/docs/api-reference/convai/twilio/outbound-call
|
35
|
+
#
|
36
|
+
# @param agent_id [String] The agent ID to use for the call
|
37
|
+
# @param agent_phone_number_id [String] The phone number ID to call from
|
38
|
+
# @param to_number [String] The phone number to call
|
39
|
+
# @param options [Hash] Optional parameters
|
40
|
+
# @option options [Hash] :conversation_initiation_client_data Additional data for conversation initiation
|
41
|
+
# @return [Hash] JSON response containing success status, message, conversation_id, and callSid
|
42
|
+
def twilio_call(agent_id:, agent_phone_number_id:, to_number:, **options)
|
43
|
+
endpoint = "/v1/convai/twilio/outbound-call"
|
44
|
+
request_body = {
|
45
|
+
agent_id: agent_id,
|
46
|
+
agent_phone_number_id: agent_phone_number_id,
|
47
|
+
to_number: to_number
|
48
|
+
}.merge(options)
|
49
|
+
|
50
|
+
@client.post(endpoint, request_body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|