Skip to content

Commit fd43104

Browse files
authored
Merge pull request #370 from deepgram/feat/agent-v1
feat: support agent v1
2 parents 5afd497 + db4d22e commit fd43104

28 files changed

+1824
-1324
lines changed

Deepgram/Clients/Agent/v2/Websocket/Client.cs

Lines changed: 828 additions & 865 deletions
Large diffs are not rendered by default.

Deepgram/Clients/Agent/v2/Websocket/UriSegments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public static class UriSegments
1212

1313
//using constants instead of inline value(magic strings) make consistence
1414
//across SDK And Test Projects Simpler and Easier to change
15-
public const string AGENT = "agent";
15+
public const string AGENT = "v1/agent/converse";
1616
}
Lines changed: 183 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,183 @@
1-
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
2-
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
3-
// SPDX-License-Identifier: MIT
4-
5-
using Deepgram.Models.Agent.v2.WebSocket;
6-
7-
namespace Deepgram.Clients.Interfaces.v2;
8-
9-
/// <summary>
10-
/// Implements version 2 of the Agent Client.
11-
/// </summary>
12-
public interface IAgentWebSocketClient
13-
{
14-
#region Connect and Disconnect
15-
/// <summary>
16-
/// Connects to the Deepgram WebSocket API
17-
/// </summary>
18-
public Task<bool> Connect(SettingsConfigurationSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
19-
Dictionary<string, string>? headers = null);
20-
21-
/// <summary>
22-
/// Disconnects from the Deepgram WebSocket API
23-
/// </summary>
24-
public Task<bool> Stop(CancellationTokenSource? cancelToken = null, bool nullByte = false);
25-
#endregion
26-
27-
#region Subscribe Event
28-
/// <summary>
29-
/// Subscribe to an Open event from the Deepgram API
30-
/// </summary>
31-
/// <param name="eventHandler"></param>
32-
/// <returns>True if successful</returns>
33-
public Task<bool> Subscribe(EventHandler<OpenResponse> eventHandler);
34-
35-
/// <summary>
36-
/// Subscribe to an Audio Binary event from the Deepgram API
37-
/// </summary>
38-
/// <param name="eventHandler"></param>
39-
/// <returns>True if successful</returns>
40-
public Task<bool> Subscribe(EventHandler<AudioResponse> eventHandler);
41-
42-
/// <summary>
43-
/// Subscribe to a AgentAudioDone event from the Deepgram API
44-
/// </summary>
45-
/// <param name="eventHandler"></param>
46-
/// <returns>True if successful</returns>
47-
public Task<bool> Subscribe(EventHandler<AgentAudioDoneResponse> eventHandler);
48-
49-
/// <summary>
50-
/// Subscribe to a AgentStartedSpeaking event from the Deepgram API
51-
/// </summary>
52-
/// <returns>True if successful</returns>
53-
public Task<bool> Subscribe(EventHandler<AgentStartedSpeakingResponse> eventHandler)
54-
;
55-
/// <summary>
56-
/// Subscribe to an AgentThinking event from the Deepgram API
57-
/// </summary>
58-
/// <returns>True if successful</returns>
59-
public Task<bool> Subscribe(EventHandler<AgentThinkingResponse> eventHandler);
60-
61-
/// <summary>
62-
/// Subscribe to a ConversationText event from the Deepgram API
63-
/// </summary>
64-
/// <returns>True if successful</returns>
65-
public Task<bool> Subscribe(EventHandler<ConversationTextResponse> eventHandler);
66-
67-
/// <summary>
68-
/// Subscribe to a FunctionCalling event from the Deepgram API
69-
/// </summary>
70-
/// <returns>True if successful</returns>
71-
public Task<bool> Subscribe(EventHandler<FunctionCallingResponse> eventHandler);
72-
73-
/// <summary>
74-
/// Subscribe to a FunctionCallRequest event from the Deepgram API
75-
/// </summary>
76-
/// <returns>True if successful</returns>
77-
public Task<bool> Subscribe(EventHandler<FunctionCallRequestResponse> eventHandler);
78-
79-
/// <summary>
80-
/// Subscribe to a UserStartedSpeaking event from the Deepgram API
81-
/// </summary>
82-
/// <returns>True if successful</returns>
83-
public Task<bool> Subscribe(EventHandler<UserStartedSpeakingResponse> eventHandler);
84-
85-
/// <summary>
86-
/// Subscribe to a Welcome event from the Deepgram API
87-
/// </summary>
88-
/// <returns>True if successful</returns>
89-
public Task<bool> Subscribe(EventHandler<WelcomeResponse> eventHandler);
90-
91-
/// <summary>
92-
/// Subscribe to a Close event from the Deepgram API
93-
/// </summary>
94-
/// <returns>True if successful</returns>
95-
public Task<bool> Subscribe(EventHandler<CloseResponse> eventHandler);
96-
97-
/// <summary>
98-
/// Subscribe to an Unhandled event from the Deepgram API
99-
/// </summary>
100-
/// <returns>True if successful</returns>
101-
public Task<bool> Subscribe(EventHandler<UnhandledResponse> eventHandler);
102-
103-
/// <summary>
104-
/// Subscribe to an Error event from the Deepgram API
105-
/// </summary>
106-
/// <returns>True if successful</returns>
107-
public Task<bool> Subscribe(EventHandler<ErrorResponse> eventHandler);
108-
109-
/// <summary>
110-
/// Subscribe to a SettingsApplied event from the Deepgram API
111-
/// </summary>
112-
/// <returns>True if successful</returns>
113-
public Task<bool> Subscribe(EventHandler<SettingsAppliedResponse> eventHandler);
114-
115-
/// <summary>
116-
/// Subscribe to an InjectionRefused event from the Deepgram API
117-
/// </summary>
118-
/// <returns>True if successful</returns>
119-
public Task<bool> Subscribe(EventHandler<InjectionRefusedResponse> eventHandler);
120-
121-
/// <summary>
122-
/// Subscribe to an InstructionsUpdated event from the Deepgram API
123-
/// </summary>
124-
/// <returns>True if successful</returns>
125-
public Task<bool> Subscribe(EventHandler<InstructionsUpdatedResponse> eventHandler);
126-
127-
/// <summary>
128-
/// Subscribe to a SpeakUpdated event from the Deepgram API
129-
/// </summary>
130-
/// <returns>True if successful</returns>
131-
public Task<bool> Subscribe(EventHandler<SpeakUpdatedResponse> eventHandler);
132-
#endregion
133-
134-
#region Send Functions
135-
/// <summary>
136-
/// Sends a KeepAlive message to Deepgram
137-
/// </summary>
138-
public Task SendKeepAlive();
139-
140-
/// <summary>
141-
/// Sends a Close message to Deepgram
142-
/// </summary>
143-
public Task SendClose(bool nullByte = false, CancellationTokenSource? _cancellationToken = null);
144-
145-
/// <summary>
146-
/// This method sends a binary message over the WebSocket connection.
147-
/// </summary>
148-
/// <param name="data"></param>
149-
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
150-
public void SendBinary(byte[] data, int length = Constants.UseArrayLengthForSend);
151-
152-
/// <summary>
153-
/// This method sends a text message over the WebSocket connection.
154-
/// </summary>
155-
/// <param name="data"></param>
156-
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
157-
public void SendMessage(byte[] data, int length = Constants.UseArrayLengthForSend);
158-
159-
/// <summary>
160-
/// This method sends a binary message over the WebSocket connection immediately without queueing.
161-
/// </summary>
162-
/// <param name="data"></param>
163-
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
164-
/// /// <param name="_cancellationToken">Provide a cancel token to be used for the send function or use the internal one</param>
165-
public Task SendBinaryImmediately(byte[] data, int length = Constants.UseArrayLengthForSend, CancellationTokenSource? _cancellationToken = null);
166-
167-
/// <summary>
168-
/// This method sends a text message over the WebSocket connection immediately without queueing.
169-
/// </summary>
170-
/// <param name="data"></param>
171-
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
172-
/// /// <param name="_cancellationToken">Provide a cancel token to be used for the send function or use the internal one</param>
173-
public Task SendMessageImmediately(byte[] data, int length = Constants.UseArrayLengthForSend, CancellationTokenSource? _cancellationToken = null);
174-
#endregion
175-
176-
#region Helpers
177-
/// <summary>
178-
/// Retrieves the connection state of the WebSocket
179-
/// </summary>
180-
/// <returns>Returns the connection state of the WebSocket</returns>
181-
public WebSocketState State();
182-
183-
/// <summary>
184-
/// Indicates whether the WebSocket is connected
185-
/// </summary>
186-
/// <returns>Returns true if the WebSocket is connected</returns>
187-
public bool IsConnected();
188-
#endregion
189-
}
1+
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
2+
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
3+
// SPDX-License-Identifier: MIT
4+
5+
using Deepgram.Models.Agent.v2.WebSocket;
6+
7+
namespace Deepgram.Clients.Interfaces.v2;
8+
9+
/// <summary>
10+
/// Implements version 2 of the Agent Client.
11+
/// </summary>
12+
public interface IAgentWebSocketClient
13+
{
14+
#region Connect and Disconnect
15+
/// <summary>
16+
/// Connects to the Deepgram WebSocket API
17+
/// </summary>
18+
public Task<bool> Connect(SettingsSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
19+
Dictionary<string, string>? headers = null);
20+
21+
/// <summary>
22+
/// Disconnects from the Deepgram WebSocket API
23+
/// </summary>
24+
public Task<bool> Stop(CancellationTokenSource? cancelToken = null, bool nullByte = false);
25+
#endregion
26+
27+
#region Subscribe Event
28+
/// <summary>
29+
/// Subscribe to an Open event from the Deepgram API
30+
/// </summary>
31+
/// <param name="eventHandler"></param>
32+
/// <returns>True if successful</returns>
33+
public Task<bool> Subscribe(EventHandler<OpenResponse> eventHandler);
34+
35+
/// <summary>
36+
/// Subscribe to an Audio Binary event from the Deepgram API
37+
/// </summary>
38+
/// <param name="eventHandler"></param>
39+
/// <returns>True if successful</returns>
40+
public Task<bool> Subscribe(EventHandler<AudioResponse> eventHandler);
41+
42+
/// <summary>
43+
/// Subscribe to a AgentAudioDone event from the Deepgram API
44+
/// </summary>
45+
/// <param name="eventHandler"></param>
46+
/// <returns>True if successful</returns>
47+
public Task<bool> Subscribe(EventHandler<AgentAudioDoneResponse> eventHandler);
48+
49+
/// <summary>
50+
/// Subscribe to a AgentStartedSpeaking event from the Deepgram API
51+
/// </summary>
52+
/// <returns>True if successful</returns>
53+
public Task<bool> Subscribe(EventHandler<AgentStartedSpeakingResponse> eventHandler)
54+
;
55+
/// <summary>
56+
/// Subscribe to an AgentThinking event from the Deepgram API
57+
/// </summary>
58+
/// <returns>True if successful</returns>
59+
public Task<bool> Subscribe(EventHandler<AgentThinkingResponse> eventHandler);
60+
61+
/// <summary>
62+
/// Subscribe to a ConversationText event from the Deepgram API
63+
/// </summary>
64+
/// <returns>True if successful</returns>
65+
public Task<bool> Subscribe(EventHandler<ConversationTextResponse> eventHandler);
66+
67+
/// <summary>
68+
/// Subscribe to a FunctionCallRequest event from the Deepgram API
69+
/// </summary>
70+
/// <returns>True if successful</returns>
71+
public Task<bool> Subscribe(EventHandler<FunctionCallRequestResponse> eventHandler);
72+
73+
/// <summary>
74+
/// Subscribe to a UserStartedSpeaking event from the Deepgram API
75+
/// </summary>
76+
/// <returns>True if successful</returns>
77+
public Task<bool> Subscribe(EventHandler<UserStartedSpeakingResponse> eventHandler);
78+
79+
/// <summary>
80+
/// Subscribe to a Welcome event from the Deepgram API
81+
/// </summary>
82+
/// <returns>True if successful</returns>
83+
public Task<bool> Subscribe(EventHandler<WelcomeResponse> eventHandler);
84+
85+
/// <summary>
86+
/// Subscribe to a Close event from the Deepgram API
87+
/// </summary>
88+
/// <returns>True if successful</returns>
89+
public Task<bool> Subscribe(EventHandler<CloseResponse> eventHandler);
90+
91+
/// <summary>
92+
/// Subscribe to an Unhandled event from the Deepgram API
93+
/// </summary>
94+
/// <returns>True if successful</returns>
95+
public Task<bool> Subscribe(EventHandler<UnhandledResponse> eventHandler);
96+
97+
/// <summary>
98+
/// Subscribe to an Error event from the Deepgram API
99+
/// </summary>
100+
/// <returns>True if successful</returns>
101+
public Task<bool> Subscribe(EventHandler<ErrorResponse> eventHandler);
102+
103+
/// <summary>
104+
/// Subscribe to a SettingsApplied event from the Deepgram API
105+
/// </summary>
106+
/// <returns>True if successful</returns>
107+
public Task<bool> Subscribe(EventHandler<SettingsAppliedResponse> eventHandler);
108+
109+
/// <summary>
110+
/// Subscribe to an InjectionRefused event from the Deepgram API
111+
/// </summary>
112+
/// <returns>True if successful</returns>
113+
public Task<bool> Subscribe(EventHandler<InjectionRefusedResponse> eventHandler);
114+
115+
/// <summary>
116+
/// Subscribe to an InstructionsUpdated event from the Deepgram API
117+
/// </summary>
118+
/// <returns>True if successful</returns>
119+
public Task<bool> Subscribe(EventHandler<PromptUpdatedResponse> eventHandler);
120+
121+
/// <summary>
122+
/// Subscribe to a SpeakUpdated event from the Deepgram API
123+
/// </summary>
124+
/// <returns>True if successful</returns>
125+
public Task<bool> Subscribe(EventHandler<SpeakUpdatedResponse> eventHandler);
126+
#endregion
127+
128+
#region Send Functions
129+
/// <summary>
130+
/// Sends a KeepAlive message to Deepgram
131+
/// </summary>
132+
public Task SendKeepAlive();
133+
134+
/// <summary>
135+
/// Sends a Close message to Deepgram
136+
/// </summary>
137+
public Task SendClose(bool nullByte = false, CancellationTokenSource? _cancellationToken = null);
138+
139+
/// <summary>
140+
/// This method sends a binary message over the WebSocket connection.
141+
/// </summary>
142+
/// <param name="data"></param>
143+
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
144+
public void SendBinary(byte[] data, int length = Constants.UseArrayLengthForSend);
145+
146+
/// <summary>
147+
/// This method sends a text message over the WebSocket connection.
148+
/// </summary>
149+
/// <param name="data"></param>
150+
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
151+
public void SendMessage(byte[] data, int length = Constants.UseArrayLengthForSend);
152+
153+
/// <summary>
154+
/// This method sends a binary message over the WebSocket connection immediately without queueing.
155+
/// </summary>
156+
/// <param name="data"></param>
157+
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
158+
/// /// <param name="_cancellationToken">Provide a cancel token to be used for the send function or use the internal one</param>
159+
public Task SendBinaryImmediately(byte[] data, int length = Constants.UseArrayLengthForSend, CancellationTokenSource? _cancellationToken = null);
160+
161+
/// <summary>
162+
/// This method sends a text message over the WebSocket connection immediately without queueing.
163+
/// </summary>
164+
/// <param name="data"></param>
165+
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
166+
/// /// <param name="_cancellationToken">Provide a cancel token to be used for the send function or use the internal one</param>
167+
public Task SendMessageImmediately(byte[] data, int length = Constants.UseArrayLengthForSend, CancellationTokenSource? _cancellationToken = null);
168+
#endregion
169+
170+
#region Helpers
171+
/// <summary>
172+
/// Retrieves the connection state of the WebSocket
173+
/// </summary>
174+
/// <returns>Returns the connection state of the WebSocket</returns>
175+
public WebSocketState State();
176+
177+
/// <summary>
178+
/// Indicates whether the WebSocket is connected
179+
/// </summary>
180+
/// <returns>Returns true if the WebSocket is connected</returns>
181+
public bool IsConnected();
182+
#endregion
183+
}

0 commit comments

Comments
 (0)