diff --git a/src/libs/Guardrails/Generated/Guardrails.AutoSDKHttpResponse.g.cs b/src/libs/Guardrails/Generated/Guardrails.AutoSDKHttpResponse.g.cs new file mode 100644 index 0000000..158f4f9 --- /dev/null +++ b/src/libs/Guardrails/Generated/Guardrails.AutoSDKHttpResponse.g.cs @@ -0,0 +1,121 @@ + +#nullable enable + +namespace Guardrails +{ + /// + /// Represents a successful HTTP response with status code and headers. + /// + public partial class AutoSDKHttpResponse + { + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers) + : this( + statusCode: statusCode, + headers: headers, + requestUri: null) + { + } + + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + global::System.Uri? requestUri) + { + StatusCode = statusCode; + Headers = headers ?? throw new global::System.ArgumentNullException(nameof(headers)); + RequestUri = requestUri; + } + + /// + /// Gets the HTTP status code. + /// + public global::System.Net.HttpStatusCode StatusCode { get; } + /// + /// Gets the response headers. + /// + public global::System.Collections.Generic.Dictionary> Headers { get; } + /// + /// Gets the final request URI associated with the response. + /// + public global::System.Uri? RequestUri { get; } + + internal static global::System.Collections.Generic.Dictionary> CreateHeaders( + global::System.Net.Http.HttpResponseMessage response) + { + response = response ?? throw new global::System.ArgumentNullException(nameof(response)); + + var headers = global::System.Linq.Enumerable.ToDictionary( + response.Headers, + static header => header.Key, + static header => (global::System.Collections.Generic.IEnumerable)global::System.Linq.Enumerable.ToArray(header.Value), + global::System.StringComparer.OrdinalIgnoreCase); + + if (response.Content?.Headers == null) + { + return headers; + } + + foreach (var header in response.Content.Headers) + { + if (headers.TryGetValue(header.Key, out var existingValues)) + { + headers[header.Key] = global::System.Linq.Enumerable.ToArray( + global::System.Linq.Enumerable.Concat(existingValues, header.Value)); + } + else + { + headers[header.Key] = global::System.Linq.Enumerable.ToArray(header.Value); + } + } + + return headers; + } + } + + /// + /// Represents a successful HTTP response with status code, headers, and body. + /// + public partial class AutoSDKHttpResponse : AutoSDKHttpResponse + { + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + T body) + : this( + statusCode: statusCode, + headers: headers, + requestUri: null, + body: body) + { + } + + /// + /// Initializes a new instance of the class. + /// + public AutoSDKHttpResponse( + global::System.Net.HttpStatusCode statusCode, + global::System.Collections.Generic.Dictionary> headers, + global::System.Uri? requestUri, + T body) + : base(statusCode, headers, requestUri) + { + Body = body; + } + + /// + /// Gets the response body. + /// + public T Body { get; } + } +} \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.CreateGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.CreateGuard.g.cs index f8282f7..03fa54f 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.CreateGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.CreateGuard.g.cs @@ -50,6 +50,28 @@ partial void ProcessCreateGuardResponseContent( /// public async global::System.Threading.Tasks.Task CreateGuardAsync( + global::Guardrails.Guard request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await CreateGuardAsResponseAsync( + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Creates a Guard + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> CreateGuardAsResponseAsync( + global::Guardrails.Guard request, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -84,6 +106,7 @@ partial void ProcessCreateGuardResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: "/guards", baseUri: HttpClient.BaseAddress); @@ -163,6 +186,8 @@ partial void ProcessCreateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -173,6 +198,11 @@ partial void ProcessCreateGuardResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -190,6 +220,8 @@ partial void ProcessCreateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -199,8 +231,7 @@ partial void ProcessCreateGuardResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -209,6 +240,11 @@ partial void ProcessCreateGuardResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -225,14 +261,15 @@ partial void ProcessCreateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -272,6 +309,8 @@ partial void ProcessCreateGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -292,6 +331,8 @@ partial void ProcessCreateGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -354,9 +395,13 @@ partial void ProcessCreateGuardResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -384,9 +429,13 @@ partial void ProcessCreateGuardResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.DeleteGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.DeleteGuard.g.cs index 18f1bdc..a06c8fc 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.DeleteGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.DeleteGuard.g.cs @@ -52,6 +52,26 @@ partial void ProcessDeleteGuardResponseContent( string guardName, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await DeleteGuardAsResponseAsync( + guardName: guardName, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Deletes a Guard + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> DeleteGuardAsResponseAsync( + string guardName, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -81,6 +101,7 @@ partial void ProcessDeleteGuardResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}", baseUri: HttpClient.BaseAddress); @@ -154,6 +175,8 @@ partial void ProcessDeleteGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -164,6 +187,11 @@ partial void ProcessDeleteGuardResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -181,6 +209,8 @@ partial void ProcessDeleteGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -190,8 +220,7 @@ partial void ProcessDeleteGuardResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -200,6 +229,11 @@ partial void ProcessDeleteGuardResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -216,14 +250,15 @@ partial void ProcessDeleteGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -263,6 +298,8 @@ partial void ProcessDeleteGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -283,6 +320,8 @@ partial void ProcessDeleteGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -345,9 +384,13 @@ partial void ProcessDeleteGuardResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -375,9 +418,13 @@ partial void ProcessDeleteGuardResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuard.g.cs index 452ca4a..92b503c 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuard.g.cs @@ -56,6 +56,29 @@ partial void ProcessGetGuardResponseContent( global::System.DateTime? asOf = default, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await GetGuardAsResponseAsync( + guardName: guardName, + asOf: asOf, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Fetches a specific Guard + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> GetGuardAsResponseAsync( + string guardName, + global::System.DateTime? asOf = default, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -86,11 +109,12 @@ partial void ProcessGetGuardResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}", - baseUri: HttpClient.BaseAddress); + baseUri: HttpClient.BaseAddress); __pathBuilder - .AddOptionalParameter("asOf", asOf?.ToString("yyyy-MM-ddTHH:mm:ssZ")) + .AddOptionalParameter("asOf", asOf?.ToString("yyyy-MM-ddTHH:mm:ssZ")) ; var __path = __pathBuilder.ToString(); __path = global::Guardrails.AutoSDKRequestOptionsSupport.AppendQueryParameters( @@ -163,6 +187,8 @@ partial void ProcessGetGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -173,6 +199,11 @@ partial void ProcessGetGuardResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -190,6 +221,8 @@ partial void ProcessGetGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -199,8 +232,7 @@ partial void ProcessGetGuardResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -209,6 +241,11 @@ partial void ProcessGetGuardResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -225,14 +262,15 @@ partial void ProcessGetGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -272,6 +310,8 @@ partial void ProcessGetGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -292,6 +332,8 @@ partial void ProcessGetGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -354,9 +396,13 @@ partial void ProcessGetGuardResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -384,9 +430,13 @@ partial void ProcessGetGuardResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuardHistory.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuardHistory.g.cs index c286f83..483a16d 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuardHistory.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuardHistory.g.cs @@ -56,6 +56,29 @@ partial void ProcessGetGuardHistoryResponseContent( string callId, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await GetGuardHistoryAsResponseAsync( + guardName: guardName, + callId: callId, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Fetches the history for a specific Guard execution by using the id for the most recent Call + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task>> GetGuardHistoryAsResponseAsync( + string guardName, + string callId, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -86,6 +109,7 @@ partial void ProcessGetGuardHistoryResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}/history/{callId}", baseUri: HttpClient.BaseAddress); @@ -160,6 +184,8 @@ partial void ProcessGetGuardHistoryResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -170,6 +196,11 @@ partial void ProcessGetGuardHistoryResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -187,6 +218,8 @@ partial void ProcessGetGuardHistoryResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -196,8 +229,7 @@ partial void ProcessGetGuardHistoryResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -206,6 +238,11 @@ partial void ProcessGetGuardHistoryResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -222,14 +259,15 @@ partial void ProcessGetGuardHistoryResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -269,6 +307,8 @@ partial void ProcessGetGuardHistoryResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -289,6 +329,8 @@ partial void ProcessGetGuardHistoryResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -351,9 +393,13 @@ partial void ProcessGetGuardHistoryResponseContent( { __response.EnsureSuccessStatusCode(); - return - (global::System.Collections.Generic.IList?)global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext) ?? + var __value = (global::System.Collections.Generic.IList?)global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse>( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -381,9 +427,13 @@ partial void ProcessGetGuardHistoryResponseContent( #endif ).ConfigureAwait(false); - return - (global::System.Collections.Generic.IList?)await global::System.Text.Json.JsonSerializer.DeserializeAsync(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext).ConfigureAwait(false) ?? + var __value = (global::System.Collections.Generic.IList?)await global::System.Text.Json.JsonSerializer.DeserializeAsync(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse>( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuards.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuards.g.cs index 1e0b4b1..8eb48b1 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuards.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.GetGuards.g.cs @@ -48,6 +48,23 @@ partial void ProcessGetGuardsResponseContent( public async global::System.Threading.Tasks.Task> GetGuardsAsync( global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await GetGuardsAsResponseAsync( + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Fetches the configuration for all Guards the user has access to. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task>> GetGuardsAsResponseAsync( + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -76,6 +93,7 @@ partial void ProcessGetGuardsResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: "/guards", baseUri: HttpClient.BaseAddress); @@ -148,6 +166,8 @@ partial void ProcessGetGuardsResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -158,6 +178,11 @@ partial void ProcessGetGuardsResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -175,6 +200,8 @@ partial void ProcessGetGuardsResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -184,8 +211,7 @@ partial void ProcessGetGuardsResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -194,6 +220,11 @@ partial void ProcessGetGuardsResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -210,14 +241,15 @@ partial void ProcessGetGuardsResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -257,6 +289,8 @@ partial void ProcessGetGuardsResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -277,6 +311,8 @@ partial void ProcessGetGuardsResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -339,9 +375,13 @@ partial void ProcessGetGuardsResponseContent( { __response.EnsureSuccessStatusCode(); - return - (global::System.Collections.Generic.IList?)global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext) ?? + var __value = (global::System.Collections.Generic.IList?)global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse>( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -369,9 +409,13 @@ partial void ProcessGetGuardsResponseContent( #endif ).ConfigureAwait(false); - return - (global::System.Collections.Generic.IList?)await global::System.Text.Json.JsonSerializer.DeserializeAsync(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext).ConfigureAwait(false) ?? + var __value = (global::System.Collections.Generic.IList?)await global::System.Text.Json.JsonSerializer.DeserializeAsync(__content, typeof(global::System.Collections.Generic.IList), JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse>( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.UpdateGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.UpdateGuard.g.cs index 2b562e0..0faa934 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.UpdateGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.UpdateGuard.g.cs @@ -54,6 +54,31 @@ partial void ProcessUpdateGuardResponseContent( public async global::System.Threading.Tasks.Task UpdateGuardAsync( string guardName, + global::Guardrails.Guard request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await UpdateGuardAsResponseAsync( + guardName: guardName, + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Updates a Guard + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> UpdateGuardAsResponseAsync( + string guardName, + global::Guardrails.Guard request, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -89,6 +114,7 @@ partial void ProcessUpdateGuardResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}", baseUri: HttpClient.BaseAddress); @@ -169,6 +195,8 @@ partial void ProcessUpdateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -179,6 +207,11 @@ partial void ProcessUpdateGuardResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -196,6 +229,8 @@ partial void ProcessUpdateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -205,8 +240,7 @@ partial void ProcessUpdateGuardResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -215,6 +249,11 @@ partial void ProcessUpdateGuardResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -231,14 +270,15 @@ partial void ProcessUpdateGuardResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -278,6 +318,8 @@ partial void ProcessUpdateGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -298,6 +340,8 @@ partial void ProcessUpdateGuardResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -360,9 +404,13 @@ partial void ProcessUpdateGuardResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.Guard.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -390,9 +438,13 @@ partial void ProcessUpdateGuardResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.Guard.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardClient.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardClient.g.cs index b13649b..c8c441c 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardClient.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardClient.g.cs @@ -72,10 +72,10 @@ public GuardClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public GuardClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Guardrails.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Guardrails.AutoSDKClientOptions? options, bool disposeHttpClient = true) { diff --git a/src/libs/Guardrails/Generated/Guardrails.GuardrailsClient.g.cs b/src/libs/Guardrails/Generated/Guardrails.GuardrailsClient.g.cs index 4d206ad..7bd5720 100644 --- a/src/libs/Guardrails/Generated/Guardrails.GuardrailsClient.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.GuardrailsClient.g.cs @@ -43,7 +43,7 @@ public sealed partial class GuardrailsClient : global::Guardrails.IGuardrailsCli /// /// /// - public GuardClient Guard => new GuardClient(HttpClient, authorizations: Authorizations, options: Options) + public GuardClient Guard => new GuardClient(HttpClient, baseUri: null, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -52,7 +52,7 @@ public sealed partial class GuardrailsClient : global::Guardrails.IGuardrailsCli /// /// /// - public OpenaiClient Openai => new OpenaiClient(HttpClient, authorizations: Authorizations, options: Options) + public OpenaiClient Openai => new OpenaiClient(HttpClient, baseUri: null, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -61,7 +61,7 @@ public sealed partial class GuardrailsClient : global::Guardrails.IGuardrailsCli /// /// /// - public ServiceHealthClient ServiceHealth => new ServiceHealthClient(HttpClient, authorizations: Authorizations, options: Options) + public ServiceHealthClient ServiceHealth => new ServiceHealthClient(HttpClient, baseUri: null, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -70,7 +70,7 @@ public sealed partial class GuardrailsClient : global::Guardrails.IGuardrailsCli /// /// /// - public ValidateClient Validate => new ValidateClient(HttpClient, authorizations: Authorizations, options: Options) + public ValidateClient Validate => new ValidateClient(HttpClient, baseUri: null, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -109,10 +109,10 @@ public GuardrailsClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public GuardrailsClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Guardrails.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Guardrails.AutoSDKClientOptions? options, bool disposeHttpClient = true) { diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.CreateGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.CreateGuard.g.cs index 849c1d8..85be6d8 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.CreateGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.CreateGuard.g.cs @@ -19,6 +19,18 @@ public partial interface IGuardClient /// /// Creates a Guard /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> CreateGuardAsResponseAsync( + + global::Guardrails.Guard request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Creates a Guard + /// /// /// The unique identifier for the Guard. /// diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.DeleteGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.DeleteGuard.g.cs index 8b75db2..af2d8d2 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.DeleteGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.DeleteGuard.g.cs @@ -15,5 +15,16 @@ public partial interface IGuardClient string guardName, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Deletes a Guard + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> DeleteGuardAsResponseAsync( + string guardName, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuard.g.cs index 25eb938..10e60be 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuard.g.cs @@ -17,5 +17,18 @@ public partial interface IGuardClient global::System.DateTime? asOf = default, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Fetches a specific Guard + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> GetGuardAsResponseAsync( + string guardName, + global::System.DateTime? asOf = default, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuardHistory.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuardHistory.g.cs index d549d9d..9bde7b4 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuardHistory.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuardHistory.g.cs @@ -17,5 +17,18 @@ public partial interface IGuardClient string callId, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Fetches the history for a specific Guard execution by using the id for the most recent Call + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task>> GetGuardHistoryAsResponseAsync( + string guardName, + string callId, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuards.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuards.g.cs index f749448..c8cb9b3 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuards.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.GetGuards.g.cs @@ -13,5 +13,14 @@ public partial interface IGuardClient global::System.Threading.Tasks.Task> GetGuardsAsync( global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Fetches the configuration for all Guards the user has access to. + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task>> GetGuardsAsResponseAsync( + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.UpdateGuard.g.cs b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.UpdateGuard.g.cs index d949e96..02966e4 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IGuardClient.UpdateGuard.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IGuardClient.UpdateGuard.g.cs @@ -22,6 +22,20 @@ public partial interface IGuardClient /// Updates a Guard /// /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> UpdateGuardAsResponseAsync( + string guardName, + + global::Guardrails.Guard request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Updates a Guard + /// + /// /// /// The unique identifier for the Guard. /// diff --git a/src/libs/Guardrails/Generated/Guardrails.IOpenaiClient.OpenaiChatCompletion.g.cs b/src/libs/Guardrails/Generated/Guardrails.IOpenaiClient.OpenaiChatCompletion.g.cs index 120324d..322a8c2 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IOpenaiClient.OpenaiChatCompletion.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IOpenaiClient.OpenaiChatCompletion.g.cs @@ -22,6 +22,20 @@ public partial interface IOpenaiClient /// OpenAI SDK compatible endpoint for Chat Completions /// /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> OpenaiChatCompletionAsResponseAsync( + string guardName, + + global::Guardrails.OpenAIChatCompletionPayload request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// OpenAI SDK compatible endpoint for Chat Completions + /// + /// /// /// The model to use for the completion
/// Example: gpt-3.5-turbo diff --git a/src/libs/Guardrails/Generated/Guardrails.IServiceHealthClient.HealthCheck.g.cs b/src/libs/Guardrails/Generated/Guardrails.IServiceHealthClient.HealthCheck.g.cs index 963bb15..74dc00c 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IServiceHealthClient.HealthCheck.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IServiceHealthClient.HealthCheck.g.cs @@ -13,5 +13,14 @@ public partial interface IServiceHealthClient global::System.Threading.Tasks.Task HealthCheckAsync( global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Returns the status of the server + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> HealthCheckAsResponseAsync( + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Guardrails/Generated/Guardrails.IValidateClient.Validate.g.cs b/src/libs/Guardrails/Generated/Guardrails.IValidateClient.Validate.g.cs index 60d161a..01e7109 100644 --- a/src/libs/Guardrails/Generated/Guardrails.IValidateClient.Validate.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.IValidateClient.Validate.g.cs @@ -25,6 +25,22 @@ public partial interface IValidateClient /// /// /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> ValidateAsResponseAsync( + string guardName, + + global::Guardrails.ValidatePayload request, + string? xOpenaiApiKey = default, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Runs the validations specified in a Guard + /// + /// + /// /// /// The LLM output as a string or the input prompts for the LLM
/// Example: stubbed llm output diff --git a/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.OpenaiChatCompletion.g.cs b/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.OpenaiChatCompletion.g.cs index 69aa870..eab0b7c 100644 --- a/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.OpenaiChatCompletion.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.OpenaiChatCompletion.g.cs @@ -54,6 +54,31 @@ partial void ProcessOpenaiChatCompletionResponseContent( public async global::System.Threading.Tasks.Task OpenaiChatCompletionAsync( string guardName, + global::Guardrails.OpenAIChatCompletionPayload request, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await OpenaiChatCompletionAsResponseAsync( + guardName: guardName, + + request: request, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// OpenAI SDK compatible endpoint for Chat Completions + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> OpenaiChatCompletionAsResponseAsync( + string guardName, + global::Guardrails.OpenAIChatCompletionPayload request, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) @@ -89,6 +114,7 @@ partial void ProcessOpenaiChatCompletionResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}/openai/v1/chat/completions", baseUri: HttpClient.BaseAddress); @@ -169,6 +195,8 @@ partial void ProcessOpenaiChatCompletionResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -179,6 +207,11 @@ partial void ProcessOpenaiChatCompletionResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -196,6 +229,8 @@ partial void ProcessOpenaiChatCompletionResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -205,8 +240,7 @@ partial void ProcessOpenaiChatCompletionResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -215,6 +249,11 @@ partial void ProcessOpenaiChatCompletionResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -231,14 +270,15 @@ partial void ProcessOpenaiChatCompletionResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -278,6 +318,8 @@ partial void ProcessOpenaiChatCompletionResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -298,6 +340,8 @@ partial void ProcessOpenaiChatCompletionResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -360,9 +404,13 @@ partial void ProcessOpenaiChatCompletionResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.OpenAIChatCompletion.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.OpenAIChatCompletion.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -390,9 +438,13 @@ partial void ProcessOpenaiChatCompletionResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.OpenAIChatCompletion.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.OpenAIChatCompletion.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.g.cs b/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.g.cs index d5a5698..f473bfb 100644 --- a/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.OpenaiClient.g.cs @@ -72,10 +72,10 @@ public OpenaiClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public OpenaiClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Guardrails.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Guardrails.AutoSDKClientOptions? options, bool disposeHttpClient = true) { diff --git a/src/libs/Guardrails/Generated/Guardrails.OptionsSupport.g.cs b/src/libs/Guardrails/Generated/Guardrails.OptionsSupport.g.cs index e79d3d5..6fc5595 100644 --- a/src/libs/Guardrails/Generated/Guardrails.OptionsSupport.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.OptionsSupport.g.cs @@ -101,9 +101,45 @@ public sealed class AutoSDKRetryOptions public int MaxAttempts { get; set; } = 1; /// - /// Optional fixed delay between retry attempts. + /// Optional fixed delay between retry attempts. When set, this takes precedence over exponential backoff. /// public global::System.TimeSpan? Delay { get; set; } + + /// + /// Initial exponential backoff delay used when is not set. + /// + public global::System.TimeSpan InitialDelay { get; set; } = global::System.TimeSpan.FromSeconds(1); + + /// + /// Maximum retry delay after applying retry headers, backoff, and jitter. + /// + public global::System.TimeSpan MaxDelay { get; set; } = global::System.TimeSpan.FromSeconds(30); + + /// + /// Multiplier applied to exponential backoff after each failed attempt. + /// Values below 1 are normalized to 1. + /// + public double BackoffMultiplier { get; set; } = 2D; + + /// + /// Randomizes computed backoff by plus or minus this ratio. Values are clamped to 0..1. + /// + public double JitterRatio { get; set; } = 0.2D; + + /// + /// Whether Retry-After response headers should control retry delay when present. + /// + public bool UseRetryAfterHeader { get; set; } = true; + + /// + /// Whether a rate-limit reset response header should control retry delay when present. + /// + public bool UseRateLimitResetHeader { get; set; } + + /// + /// Optional provider-specific rate-limit reset header name. Values may be Unix seconds or an HTTP date. + /// + public string? RateLimitResetHeaderName { get; set; } = "X-RateLimit-Reset"; } @@ -231,6 +267,16 @@ public sealed class AutoSDKHookContext /// public bool WillRetry { get; set; } + /// + /// The computed retry delay when is true. + /// + public global::System.TimeSpan? RetryDelay { get; set; } + + /// + /// A short retry reason such as exception or status:429. + /// + public string RetryReason { get; set; } = string.Empty; + /// /// The effective cancellation token for the current request attempt. /// @@ -254,6 +300,8 @@ internal static class AutoSDKRequestOptionsSupport int attempt, int maxAttempts, bool willRetry, + global::System.TimeSpan? retryDelay, + string retryReason, global::System.Threading.CancellationToken cancellationToken) { return new global::Guardrails.AutoSDKHookContext @@ -271,6 +319,8 @@ internal static class AutoSDKRequestOptionsSupport Attempt = attempt, MaxAttempts = maxAttempts, WillRetry = willRetry, + RetryDelay = retryDelay, + RetryReason = retryReason ?? string.Empty, CancellationToken = cancellationToken, }; } @@ -338,19 +388,188 @@ internal static int GetMaxAttempts( return maxAttempts < 1 ? 1 : maxAttempts; } - internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + internal static global::System.TimeSpan GetRetryDelay( global::Guardrails.AutoSDKClientOptions clientOptions, global::Guardrails.AutoSDKRequestOptions? requestOptions, + global::System.Net.Http.HttpResponseMessage? response, + int attempt) + { + var retryOptions = requestOptions?.Retry ?? clientOptions.Retry ?? new global::Guardrails.AutoSDKRetryOptions(); + + if (retryOptions.UseRetryAfterHeader && + TryGetRetryAfterDelay(response, out var retryAfterDelay)) + { + return ClampRetryDelay(retryAfterDelay, retryOptions); + } + + if (retryOptions.UseRateLimitResetHeader && + TryGetRateLimitResetDelay(response, retryOptions.RateLimitResetHeaderName, out var rateLimitResetDelay)) + { + return ClampRetryDelay(rateLimitResetDelay, retryOptions); + } + + if (retryOptions.Delay.HasValue) + { + return ClampRetryDelay(retryOptions.Delay.Value, retryOptions); + } + + var initialDelay = retryOptions.InitialDelay; + if (initialDelay <= global::System.TimeSpan.Zero) + { + return global::System.TimeSpan.Zero; + } + + var multiplier = retryOptions.BackoffMultiplier < 1D ? 1D : retryOptions.BackoffMultiplier; + var exponent = attempt <= 1 ? 0 : attempt - 1; + var delayMilliseconds = initialDelay.TotalMilliseconds * global::System.Math.Pow(multiplier, exponent); + if (double.IsNaN(delayMilliseconds) || double.IsInfinity(delayMilliseconds) || delayMilliseconds < 0D) + { + delayMilliseconds = 0D; + } + + var delay = global::System.TimeSpan.FromMilliseconds(delayMilliseconds); + delay = ApplyJitter(delay, retryOptions.JitterRatio); + return ClampRetryDelay(delay, retryOptions); + } + + internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + global::System.TimeSpan retryDelay, global::System.Threading.CancellationToken cancellationToken) { - var delay = requestOptions?.Retry?.Delay ?? - clientOptions.Retry?.Delay; - if (!delay.HasValue || delay.Value <= global::System.TimeSpan.Zero) + if (retryDelay <= global::System.TimeSpan.Zero) { return; } - await global::System.Threading.Tasks.Task.Delay(delay.Value, cancellationToken).ConfigureAwait(false); + await global::System.Threading.Tasks.Task.Delay(retryDelay, cancellationToken).ConfigureAwait(false); + } + + private static bool TryGetRetryAfterDelay( + global::System.Net.Http.HttpResponseMessage? response, + out global::System.TimeSpan delay) + { + delay = global::System.TimeSpan.Zero; + var retryAfter = response?.Headers.RetryAfter; + if (retryAfter == null) + { + return false; + } + + if (retryAfter.Delta.HasValue) + { + delay = retryAfter.Delta.Value; + return delay > global::System.TimeSpan.Zero; + } + + if (retryAfter.Date.HasValue) + { + delay = retryAfter.Date.Value - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + return false; + } + + private static bool TryGetRateLimitResetDelay( + global::System.Net.Http.HttpResponseMessage? response, + string? headerName, + out global::System.TimeSpan delay) + { + delay = global::System.TimeSpan.Zero; + if (response == null || string.IsNullOrWhiteSpace(headerName)) + { + return false; + } + + if (!response.Headers.TryGetValues(headerName, out var values) && + (response.Content?.Headers == null || !response.Content.Headers.TryGetValues(headerName, out values))) + { + return false; + } + + var value = global::System.Linq.Enumerable.FirstOrDefault(values); + if (string.IsNullOrWhiteSpace(value)) + { + return false; + } + + value = value.Trim(); + if (long.TryParse( + value, + global::System.Globalization.NumberStyles.Integer, + global::System.Globalization.CultureInfo.InvariantCulture, + out var unixSeconds)) + { + delay = global::System.DateTimeOffset.FromUnixTimeSeconds(unixSeconds) - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + if (global::System.DateTimeOffset.TryParse( + value, + global::System.Globalization.CultureInfo.InvariantCulture, + global::System.Globalization.DateTimeStyles.AssumeUniversal | global::System.Globalization.DateTimeStyles.AdjustToUniversal, + out var resetAt)) + { + delay = resetAt - global::System.DateTimeOffset.UtcNow; + return delay > global::System.TimeSpan.Zero; + } + + return false; + } + + private static global::System.TimeSpan ApplyJitter( + global::System.TimeSpan delay, + double jitterRatio) + { + if (delay <= global::System.TimeSpan.Zero || jitterRatio <= 0D) + { + return delay; + } + + if (jitterRatio > 1D) + { + jitterRatio = 1D; + } + + var sample = NextJitterSample(); + var multiplier = 1D - jitterRatio + (sample * jitterRatio * 2D); + var milliseconds = delay.TotalMilliseconds * multiplier; + if (double.IsNaN(milliseconds) || double.IsInfinity(milliseconds) || milliseconds < 0D) + { + milliseconds = 0D; + } + + return global::System.TimeSpan.FromMilliseconds(milliseconds); + } + + private static double NextJitterSample() + { + var bytes = new byte[8]; + using (var randomNumberGenerator = global::System.Security.Cryptography.RandomNumberGenerator.Create()) + { + randomNumberGenerator.GetBytes(bytes); + } + + var value = global::System.BitConverter.ToUInt64(bytes, 0); + return value / (double)ulong.MaxValue; + } + + private static global::System.TimeSpan ClampRetryDelay( + global::System.TimeSpan delay, + global::Guardrails.AutoSDKRetryOptions retryOptions) + { + if (delay <= global::System.TimeSpan.Zero) + { + return global::System.TimeSpan.Zero; + } + + var maxDelay = retryOptions.MaxDelay; + if (maxDelay > global::System.TimeSpan.Zero && delay > maxDelay) + { + return maxDelay; + } + + return delay; } internal static bool ShouldRetryStatusCode( diff --git a/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.HealthCheck.g.cs b/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.HealthCheck.g.cs index 1ac84df..980219f 100644 --- a/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.HealthCheck.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.HealthCheck.g.cs @@ -48,6 +48,23 @@ partial void ProcessHealthCheckResponseContent( public async global::System.Threading.Tasks.Task HealthCheckAsync( global::Guardrails.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await HealthCheckAsResponseAsync( + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Returns the status of the server + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> HealthCheckAsResponseAsync( + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( client: HttpClient); @@ -76,6 +93,7 @@ partial void ProcessHealthCheckResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: "/health-check", baseUri: HttpClient.BaseAddress); @@ -148,6 +166,8 @@ partial void ProcessHealthCheckResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -158,6 +178,11 @@ partial void ProcessHealthCheckResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -175,6 +200,8 @@ partial void ProcessHealthCheckResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -184,8 +211,7 @@ partial void ProcessHealthCheckResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -194,6 +220,11 @@ partial void ProcessHealthCheckResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -210,14 +241,15 @@ partial void ProcessHealthCheckResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -257,6 +289,8 @@ partial void ProcessHealthCheckResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -277,6 +311,8 @@ partial void ProcessHealthCheckResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -339,9 +375,13 @@ partial void ProcessHealthCheckResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.HealthCheck.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.HealthCheck.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -369,9 +409,13 @@ partial void ProcessHealthCheckResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.HealthCheck.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.HealthCheck.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.g.cs b/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.g.cs index 791cecc..265e746 100644 --- a/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.ServiceHealthClient.g.cs @@ -72,10 +72,10 @@ public ServiceHealthClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public ServiceHealthClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Guardrails.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Guardrails.AutoSDKClientOptions? options, bool disposeHttpClient = true) { diff --git a/src/libs/Guardrails/Generated/Guardrails.ValidateClient.Validate.g.cs b/src/libs/Guardrails/Generated/Guardrails.ValidateClient.Validate.g.cs index 21059b5..8cd73ca 100644 --- a/src/libs/Guardrails/Generated/Guardrails.ValidateClient.Validate.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.ValidateClient.Validate.g.cs @@ -57,6 +57,34 @@ partial void ProcessValidateResponseContent( public async global::System.Threading.Tasks.Task ValidateAsync( string guardName, + global::Guardrails.ValidatePayload request, + string? xOpenaiApiKey = default, + global::Guardrails.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + var __response = await ValidateAsResponseAsync( + guardName: guardName, + + request: request, + xOpenaiApiKey: xOpenaiApiKey, + requestOptions: requestOptions, + cancellationToken: cancellationToken + ).ConfigureAwait(false); + + return __response.Body; + } + /// + /// Runs the validations specified in a Guard + /// + /// + /// + /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> ValidateAsResponseAsync( + string guardName, + global::Guardrails.ValidatePayload request, string? xOpenaiApiKey = default, global::Guardrails.AutoSDKRequestOptions? requestOptions = default, @@ -94,6 +122,7 @@ partial void ProcessValidateResponseContent( global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() { + var __pathBuilder = new global::Guardrails.PathBuilder( path: $"/guards/{guardName}/validate", baseUri: HttpClient.BaseAddress); @@ -181,6 +210,8 @@ partial void ProcessValidateResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); try { @@ -191,6 +222,11 @@ partial void ProcessValidateResponseContent( } catch (global::System.Net.Http.HttpRequestException __exception) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, @@ -208,6 +244,8 @@ partial void ProcessValidateResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); if (!__willRetry) { @@ -217,8 +255,7 @@ partial void ProcessValidateResponseContent( __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -227,6 +264,11 @@ partial void ProcessValidateResponseContent( __attempt < __maxAttempts && global::Guardrails.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { + var __retryDelay = global::Guardrails.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); await global::Guardrails.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( clientOptions: Options, context: global::Guardrails.AutoSDKRequestOptionsSupport.CreateHookContext( @@ -243,14 +285,15 @@ partial void ProcessValidateResponseContent( attempt: __attempt, maxAttempts: __maxAttempts, willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); __response.Dispose(); __response = null; __httpRequest.Dispose(); __httpRequest = null; await global::Guardrails.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( - clientOptions: Options, - requestOptions: requestOptions, + retryDelay: __retryDelay, cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); continue; } @@ -290,6 +333,8 @@ partial void ProcessValidateResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } else @@ -310,6 +355,8 @@ partial void ProcessValidateResponseContent( attempt: __attemptNumber, maxAttempts: __maxAttempts, willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } // Unexpected error @@ -372,9 +419,13 @@ partial void ProcessValidateResponseContent( { __response.EnsureSuccessStatusCode(); - return - global::Guardrails.ValidationOutcome.FromJson(__content, JsonSerializerContext) ?? + var __value = global::Guardrails.ValidationOutcome.FromJson(__content, JsonSerializerContext) ?? throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { @@ -402,9 +453,13 @@ partial void ProcessValidateResponseContent( #endif ).ConfigureAwait(false); - return - await global::Guardrails.ValidationOutcome.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + var __value = await global::Guardrails.ValidationOutcome.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Guardrails.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Guardrails.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: __value); } catch (global::System.Exception __ex) { diff --git a/src/libs/Guardrails/Generated/Guardrails.ValidateClient.g.cs b/src/libs/Guardrails/Generated/Guardrails.ValidateClient.g.cs index a54bab4..309d85a 100644 --- a/src/libs/Guardrails/Generated/Guardrails.ValidateClient.g.cs +++ b/src/libs/Guardrails/Generated/Guardrails.ValidateClient.g.cs @@ -72,10 +72,10 @@ public ValidateClient( /// Client-wide request defaults such as headers, query parameters, retries, and timeout. /// Dispose the HttpClient when the instance is disposed. True by default. public ValidateClient( - global::System.Net.Http.HttpClient? httpClient = null, - global::System.Uri? baseUri = null, - global::System.Collections.Generic.List? authorizations = null, - global::Guardrails.AutoSDKClientOptions? options = null, + global::System.Net.Http.HttpClient? httpClient, + global::System.Uri? baseUri, + global::System.Collections.Generic.List? authorizations, + global::Guardrails.AutoSDKClientOptions? options, bool disposeHttpClient = true) {