1+
2+ #nullable enable
3+
4+ namespace Ultravox
5+ {
6+ public partial class AgentsClient
7+ {
8+ partial void PrepareAgentsRevisionsCreateArguments (
9+ global ::System . Net . Http . HttpClient httpClient ,
10+ ref global ::System . Guid agentId ,
11+ global ::Ultravox . AgentRevision request ) ;
12+ partial void PrepareAgentsRevisionsCreateRequest (
13+ global ::System . Net . Http . HttpClient httpClient ,
14+ global ::System . Net . Http . HttpRequestMessage httpRequestMessage ,
15+ global ::System . Guid agentId ,
16+ global ::Ultravox . AgentRevision request ) ;
17+ partial void ProcessAgentsRevisionsCreateResponse (
18+ global ::System . Net . Http . HttpClient httpClient ,
19+ global ::System . Net . Http . HttpResponseMessage httpResponseMessage ) ;
20+
21+ partial void ProcessAgentsRevisionsCreateResponseContent (
22+ global ::System . Net . Http . HttpClient httpClient ,
23+ global ::System . Net . Http . HttpResponseMessage httpResponseMessage ,
24+ ref string content ) ;
25+
26+ /// <summary>
27+ ///
28+ /// </summary>
29+ /// <param name="agentId"></param>
30+ /// <param name="request"></param>
31+ /// <param name="cancellationToken">The token to cancel the operation with</param>
32+ /// <exception cref="global::Ultravox.ApiException"></exception>
33+ public async global ::System . Threading . Tasks . Task < global ::Ultravox . AgentRevision > AgentsRevisionsCreateAsync (
34+ global ::System . Guid agentId ,
35+ global ::Ultravox . AgentRevision request ,
36+ global ::System . Threading . CancellationToken cancellationToken = default )
37+ {
38+ request = request ?? throw new global ::System . ArgumentNullException ( nameof ( request ) ) ;
39+
40+ PrepareArguments (
41+ client : HttpClient ) ;
42+ PrepareAgentsRevisionsCreateArguments (
43+ httpClient : HttpClient ,
44+ agentId : ref agentId ,
45+ request : request ) ;
46+
47+ var __pathBuilder = new global ::Ultravox . PathBuilder (
48+ path : $ "/api/agents/{ agentId } /revisions",
49+ baseUri : HttpClient . BaseAddress ) ;
50+ var __path = __pathBuilder . ToString ( ) ;
51+ using var __httpRequest = new global ::System . Net . Http . HttpRequestMessage (
52+ method : global ::System . Net . Http . HttpMethod . Post ,
53+ requestUri : new global ::System . Uri ( __path , global ::System . UriKind . RelativeOrAbsolute ) ) ;
54+ #if NET6_0_OR_GREATER
55+ __httpRequest . Version = global ::System . Net . HttpVersion . Version11 ;
56+ __httpRequest . VersionPolicy = global ::System . Net . Http . HttpVersionPolicy . RequestVersionOrHigher ;
57+ #endif
58+
59+ foreach ( var __authorization in Authorizations )
60+ {
61+ if ( __authorization . Type == "Http" ||
62+ __authorization . Type == "OAuth2" )
63+ {
64+ __httpRequest . Headers . Authorization = new global ::System . Net . Http . Headers . AuthenticationHeaderValue (
65+ scheme : __authorization . Name ,
66+ parameter : __authorization . Value ) ;
67+ }
68+ else if ( __authorization . Type == "ApiKey" &&
69+ __authorization . Location == "Header" )
70+ {
71+ __httpRequest . Headers . Add ( __authorization . Name , __authorization . Value ) ;
72+ }
73+ }
74+ var __httpRequestContentBody = request . ToJson ( JsonSerializerContext ) ;
75+ var __httpRequestContent = new global ::System . Net . Http . StringContent (
76+ content : __httpRequestContentBody ,
77+ encoding : global ::System . Text . Encoding . UTF8 ,
78+ mediaType : "application/json" ) ;
79+ __httpRequest . Content = __httpRequestContent ;
80+
81+ PrepareRequest (
82+ client : HttpClient ,
83+ request : __httpRequest ) ;
84+ PrepareAgentsRevisionsCreateRequest (
85+ httpClient : HttpClient ,
86+ httpRequestMessage : __httpRequest ,
87+ agentId : agentId ,
88+ request : request ) ;
89+
90+ using var __response = await HttpClient . SendAsync (
91+ request : __httpRequest ,
92+ completionOption : global ::System . Net . Http . HttpCompletionOption . ResponseContentRead ,
93+ cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
94+
95+ ProcessResponse (
96+ client : HttpClient ,
97+ response : __response ) ;
98+ ProcessAgentsRevisionsCreateResponse (
99+ httpClient : HttpClient ,
100+ httpResponseMessage : __response ) ;
101+
102+ if ( ReadResponseAsString )
103+ {
104+ var __content = await __response . Content . ReadAsStringAsync (
105+ #if NET5_0_OR_GREATER
106+ cancellationToken
107+ #endif
108+ ) . ConfigureAwait ( false ) ;
109+
110+ ProcessResponseContent (
111+ client : HttpClient ,
112+ response : __response ,
113+ content : ref __content ) ;
114+ ProcessAgentsRevisionsCreateResponseContent (
115+ httpClient : HttpClient ,
116+ httpResponseMessage : __response ,
117+ content : ref __content ) ;
118+
119+ try
120+ {
121+ __response . EnsureSuccessStatusCode ( ) ;
122+
123+ return
124+ global ::Ultravox . AgentRevision . FromJson ( __content , JsonSerializerContext ) ??
125+ throw new global ::System . InvalidOperationException ( $ "Response deserialization failed for \" { __content } \" ") ;
126+ }
127+ catch ( global ::System . Exception __ex )
128+ {
129+ throw new global ::Ultravox . ApiException (
130+ message : __content ?? __response . ReasonPhrase ?? string . Empty ,
131+ innerException : __ex ,
132+ statusCode : __response . StatusCode )
133+ {
134+ ResponseBody = __content ,
135+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
136+ __response . Headers ,
137+ h => h . Key ,
138+ h => h . Value ) ,
139+ } ;
140+ }
141+ }
142+ else
143+ {
144+ try
145+ {
146+ __response . EnsureSuccessStatusCode ( ) ;
147+
148+ using var __content = await __response . Content . ReadAsStreamAsync (
149+ #if NET5_0_OR_GREATER
150+ cancellationToken
151+ #endif
152+ ) . ConfigureAwait ( false ) ;
153+
154+ return
155+ await global ::Ultravox . AgentRevision . FromJsonStreamAsync ( __content , JsonSerializerContext ) . ConfigureAwait ( false ) ??
156+ throw new global ::System . InvalidOperationException ( "Response deserialization failed." ) ;
157+ }
158+ catch ( global ::System . Exception __ex )
159+ {
160+ throw new global ::Ultravox . ApiException (
161+ message : __response . ReasonPhrase ?? string . Empty ,
162+ innerException : __ex ,
163+ statusCode : __response . StatusCode )
164+ {
165+ ResponseHeaders = global ::System . Linq . Enumerable . ToDictionary (
166+ __response . Headers ,
167+ h => h . Key ,
168+ h => h . Value ) ,
169+ } ;
170+ }
171+ }
172+ }
173+
174+ /// <summary>
175+ ///
176+ /// </summary>
177+ /// <param name="agentId"></param>
178+ /// <param name="callTemplate">
179+ /// A CallTemplate that can be used to create Ultravox calls with shared properties.
180+ /// </param>
181+ /// <param name="cancellationToken">The token to cancel the operation with</param>
182+ /// <exception cref="global::System.InvalidOperationException"></exception>
183+ public async global ::System . Threading . Tasks . Task < global ::Ultravox . AgentRevision > AgentsRevisionsCreateAsync (
184+ global ::System . Guid agentId ,
185+ global ::Ultravox . UltravoxV1CallTemplate callTemplate ,
186+ global ::System . Threading . CancellationToken cancellationToken = default )
187+ {
188+ var __request = new global ::Ultravox . AgentRevision
189+ {
190+ CallTemplate = callTemplate ,
191+ } ;
192+
193+ return await AgentsRevisionsCreateAsync (
194+ agentId : agentId ,
195+ request : __request ,
196+ cancellationToken : cancellationToken ) . ConfigureAwait ( false ) ;
197+ }
198+ }
199+ }
0 commit comments