@@ -34,7 +34,6 @@ function Update-OpenAIClient {
34
34
$content = $content -creplace " \s+\/\/\/ <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>" , " "
35
35
$content = $content -creplace " \s+internal TelemetrySource ClientDiagnostics { get; }" , " "
36
36
$content = $content -creplace " \(KeyCredential" , " (ApiKeyCredential"
37
- $content = $content -creplace " ClientUtilities.AssertNotNull\((?<var>\w+), nameof\((\w+)\)\);" , " if (`$ {var} is null) throw new ArgumentNullException(nameof(`$ {var}));"
38
37
$content = $content -creplace " \s+ClientDiagnostics = new TelemetrySource\(options, true\);" , " "
39
38
$content = $content -creplace " _pipeline = MessagePipeline\.Create\(options, new IPipelinePolicy<PipelineMessage>\[\] \{ new KeyCredentialPolicy\(_keyCredential, AuthorizationHeader, AuthorizationApiKeyPrefix\) \}, Array\.Empty<IPipelinePolicy<PipelineMessage>>\(\)\);" , " var authenticationPolicy = ApiKeyAuthenticationPolicy.CreateBearerAuthorizationPolicy(_credential);`r`n _pipeline = ClientPipeline.Create(options,`r`n perCallPolicies: ReadOnlySpan<PipelinePolicy>.Empty,`r`n perTryPolicies: new PipelinePolicy[] { authenticationPolicy },`r`n beforeTransportPolicies: ReadOnlySpan<PipelinePolicy>.Empty);"
40
39
$content = $content -creplace " \(ClientDiagnostics, " , " ("
@@ -75,10 +74,6 @@ function Update-Subclients {
75
74
$content = $content -creplace " \s+using System.ClientModel.Primitives.Pipeline;" , " "
76
75
$content = $content -creplace " using System.ClientModel.Primitives;" , " using System.ClientModel.Primitives;`r`n using System.Text;"
77
76
78
- # Fix ClientUtilities
79
- $content = $content -creplace " ClientUtilities.AssertNotNull\((?<var>\w+), nameof\((\w+)\)\);" , " if (`$ {var} is null) throw new ArgumentNullException(nameof(`$ {var}));"
80
- $content = $content -creplace " ClientUtilities.AssertNotNullOrEmpty\((?<var>\w+), nameof\((\w+)\)\);" , " if (`$ {var} is null) throw new ArgumentNullException(nameof(`$ {var}));`r`n if (string.IsNullOrEmpty(`$ {var})) throw new ArgumentException(nameof(`$ {var}));"
81
-
82
77
# Delete TelemetrySource
83
78
$content = $content -creplace " \s+\/\/\/ <summary> The ClientDiagnostics is used to provide tracing support for the client library. </summary>" , " "
84
79
$content = $content -creplace " \s+internal TelemetrySource ClientDiagnostics { get; }" , " "
@@ -115,11 +110,10 @@ function Update-Subclients {
115
110
$content = $content -creplace " RequestBody content" , " BinaryContent content"
116
111
$content = $content -creplace " \(RequestOptions context" , " (RequestOptions options"
117
112
$content = $content -creplace " RequestOptions context" , " RequestOptions options"
118
- $content = $content -creplace " \s+using var scope = ClientDiagnostics\.CreateSpan\(`" (\w+\.\w+)`" \);" , " "
119
- $content = $content -creplace " \s+scope\.Start\(\);" , " "
120
- $content = $content -creplace " (?s)\s+try\s+\{\s+using PipelineMessage message = (?<method>\w+)\((?<params>[(\w+)(,\s\w+)]*)context\);\s+return Result\.FromResponse\(await _pipeline\.ProcessMessageAsync\(message, context\)\.ConfigureAwait\(false\)\);\s+\}" , " `r`n options ??= new RequestOptions();`r`n using PipelineMessage message = `$ {method}(`$ {params}options);`r`n await _pipeline.SendAsync(message).ConfigureAwait(false);`r`n PipelineResponse response = message.Response!;`r`n`r`n if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)`r`n {`r`n throw await ClientResultException.CreateAsync(response).ConfigureAwait(false);`r`n }`r`n`r`n return ClientResult.FromResponse(response);"
121
- $content = $content -creplace " (?s)\s+try\s+\{\s+using PipelineMessage message = (?<method>\w+)\((?<params>[(\w+)(,\s\w+)]*)context\);\s+return Result\.FromResponse\(_pipeline.ProcessMessage\(message, context\)\);\s+\}" , " `r`n options ??= new RequestOptions();`r`n using PipelineMessage message = `$ {method}(`$ {params}options);`r`n _pipeline.Send(message);`r`n PipelineResponse response = message.Response!;`r`n`r`n if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)`r`n {`r`n throw new ClientResultException(response);`r`n }`r`n`r`n return ClientResult.FromResponse(response);"
122
- $content = $content -creplace " (?s)\s+catch \(Exception e\)\s+\{\s+scope\.Failed\(e\);\s+throw;\s+\}" , " "
113
+ $content = $content -creplace " context\)" , " options)"
114
+ $content = $content -creplace " using var scope = ClientDiagnostics\.CreateSpan\(`" (?<tag>\w+)\.(?<operationId>\w+)`" \);" , " options ??= new RequestOptions();`r`n // using var scope = ClientDiagnostics.CreateSpan(`"`$ {tag}.`$ {operationId}`" \);"
115
+ $content = $content -creplace " scope\.Start\(\);" , " // scope.Start();"
116
+ $content = $content -creplace " scope\.Failed\(e\);" , " // scope.Failed(e);"
123
117
124
118
# Create request
125
119
$content = $content -creplace " \(RequestBody content" , " (BinaryContent content"
@@ -136,9 +130,6 @@ function Update-Subclients {
136
130
$content = $content -creplace " request\.SetHeaderValue" , " request.Headers.Set"
137
131
$content = $content -creplace " request\.Content = content;" , " request.Content = content;`r`n message.Apply(options);"
138
132
139
- # Delete DefaultRequestContext
140
- # $content = $content -creplace "\s+private static RequestOptions DefaultRequestContext = new RequestOptions\(\);", ""
141
-
142
133
# Clean up ApiKeyCredential
143
134
$content = $content -creplace " KeyCredential" , " ApiKeyCredential"
144
135
$content = $content -creplace " _keyCredential" , " _credential"
@@ -170,16 +161,67 @@ function Update-Models {
170
161
Write-Output " Editing $ ( $file.FullName ) "
171
162
172
163
$content = $content -creplace " \s+#nullable disable" , " "
173
- $content = $content -creplace " ClientUtilities.AssertNotNull\((?<var>@?\w+), nameof\((@?\w+)\)\) ;" , " if ( `$ {var} is null) throw new ArgumentNullException(nameof( `$ {var})) ;"
174
- $content = $content -creplace " using System.ClientModel.Internal ;" , " using OpenAI.ClientShared.Internal ;"
164
+ $content = $content -creplace " using System\.ClientModel\.Internal ;" , " using OpenAI.ClientShared.Internal ;"
165
+ $content = $content -creplace " using System\ .ClientModel\.Primitives ;" , " using System.ClientModel; `r`n using System.ClientModel.Primitives ;"
175
166
$content = $content -creplace " : IUtf8JsonWriteable," , " :"
176
167
$content = $content -creplace " \s+void IUtf8JsonWriteable\.Write\(Utf8JsonWriter writer\) => \(\(IJsonModel<(\w+)>\)this\)\.Write\(writer, new ModelReaderWriterOptions\(`" W`" \)\);`r`n " , " "
177
- $content = $content -creplace " (?s)\s+\/\/\/ <summary> Convert into a Utf8JsonRequestBody\. </summary>.*?return content;.*?\} " , " "
168
+ $content = $content -creplace " RequestBody " , " BinaryContent "
178
169
179
170
$content | Set-Content - Path $file.FullName - NoNewline
180
171
}
181
172
}
182
173
174
+ function Update-InternalClientPipelineExtensions {
175
+ $root = Split-Path $PSScriptRoot - Parent
176
+ $directory = Join-Path - Path $root - ChildPath " src\Generated\Internal"
177
+ $file = Get-ChildItem - Path $directory - Filter " ClientPipelineExtensions.cs"
178
+ $content = Get-Content - Path $file - Raw
179
+
180
+ Write-Output " Editing $ ( $file.FullName ) "
181
+
182
+ $content = $content -creplace " \s+using System\.ClientModel\.Primitives\.Pipeline;" , " "
183
+ $content = $content -creplace " Pipeline<PipelineMessage>" , " ClientPipeline"
184
+ $content = $content -creplace " \.ErrorBehavior" , " .ErrorOptions"
185
+ $content = $content -creplace " ErrorBehavior\." , " ClientErrorBehaviors."
186
+ $content = $content -creplace " MessageFailedException" , " ClientResultException"
187
+ $content = $content -creplace " (?s)\s+public static async ValueTask<NullableResult<bool>> ProcessHeadAsBoolMessageAsync.*?\}.*?\}" , " "
188
+ $content = $content -creplace " (?s)\s+public static NullableResult<bool> ProcessHeadAsBoolMessage.*?\}.*?\}" , " "
189
+
190
+ $content | Set-Content - Path $file.FullName - NoNewline
191
+ }
192
+
193
+ function Update-InternalErrorResult {
194
+ $root = Split-Path $PSScriptRoot - Parent
195
+ $directory = Join-Path - Path $root - ChildPath " src\Generated\Internal"
196
+ $file = Get-ChildItem - Path $directory - Filter " ErrorResult.cs"
197
+ $content = Get-Content - Path $file - Raw
198
+
199
+ Write-Output " Editing $ ( $file.FullName ) "
200
+
201
+ $content = $content -creplace " MessagePipeline" , " ClientPipeline"
202
+ $content = $content -creplace " Result" , " ClientResult"
203
+ $content = $content -creplace " MessageFailedException" , " ClientResultException"
204
+ $content = $content -creplace " \s+public override bool HasValue => false;" , " "
205
+ $content = $content -creplace " (?s)\s+public override PipelineResponse GetRawResponse\(\)\s+\{\s+return _response;\s+\}" , " "
206
+
207
+ $content | Set-Content - Path $file.FullName - NoNewline
208
+ }
209
+
210
+ function Update-InternalUtf8JsonRequestBody {
211
+ $root = Split-Path $PSScriptRoot - Parent
212
+ $directory = Join-Path - Path $root - ChildPath " src\Generated\Internal"
213
+ $file = Get-ChildItem - Path $directory - Filter " Utf8JsonRequestBody.cs"
214
+ $content = Get-Content - Path $file - Raw
215
+
216
+ Write-Output " Editing $ ( $file.FullName ) "
217
+
218
+ $content = $content -creplace " using System\.ClientModel\.Primitives;" , " using System;`r`n using System.ClientModel;"
219
+ $content = $content -creplace " RequestBody" , " BinaryContent"
220
+ $content = $content -creplace " _content = CreateFromStream\(_stream\);" , " _content = BinaryContent.Create(BinaryData.FromStream(_stream));"
221
+
222
+ $content | Set-Content - Path $file.FullName - NoNewline
223
+ }
224
+
183
225
function Update-Tests {
184
226
$root = Split-Path $PSScriptRoot - Parent
185
227
$directory = Join-Path - Path $root - ChildPath " tests\Generated\Tests"
@@ -201,4 +243,7 @@ Update-OpenAIClient
201
243
Update-OpenAIClientOptions
202
244
Update-Subclients
203
245
Update-Models
246
+ Update-InternalClientPipelineExtensions
247
+ Update-InternalErrorResult
248
+ Update-InternalUtf8JsonRequestBody
204
249
Update-Tests
0 commit comments