Skip to content

Commit 1708406

Browse files
committed
fix: Fixed issue with Role
1 parent d60a413 commit 1708406

16 files changed

+383
-658
lines changed

src/helpers/FixOpenApiSpec/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
openApiDocument.Components.Schemas["BetaTool"].Properties["input_schema"].AllOf.Clear();
5151
openApiDocument.Components.Schemas["BetaTool"].Properties["input_schema"].Type = "object";
5252

53+
openApiDocument.Components.Schemas["InputMessage"].Discriminator = null;
54+
openApiDocument.Components.Schemas["BetaInputMessage"].Discriminator = null;
55+
5356
openApiDocument.Components.SecuritySchemes.Clear();
5457
openApiDocument.Components.SecuritySchemes.Add("ApiKeyAuth", new OpenApiSecurityScheme
5558
{

src/libs/Anthropic/Extensions/AnthropicClient.ChatClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ private static CreateMessageParams CreateRequest(IList<ChatMessage> chatMessages
246246
: new ToolChoice(new ToolChoiceAny())
247247
: (ToolChoice?)null,
248248
Tools = options?.Tools is IList<AITool> tools ?
249-
tools.OfType<AIFunction>().Select(f => new Tool
249+
tools.OfType<AIFunction>().Select(f => new OneOf<Tool, BashTool20250124, TextEditor20250124>(new Tool
250250
{
251251
Name = f.Name,
252252
Description = f.Description,
253253
InputSchema = CreateSchema(f),
254-
}).ToList() :
254+
})).ToList() :
255255
null,
256256
};
257257
return request;

src/libs/Anthropic/Extensions/StringExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ public static string AsJson(this object args)
113113
/// </summary>
114114
/// <param name="tools"></param>
115115
/// <returns></returns>
116-
public static IList<Tool> AsAnthropicTools(
116+
public static IList<OneOf<Tool, BashTool20250124, TextEditor20250124>> AsAnthropicTools(
117117
this IList<CSharpToJsonSchema.Tool> tools)
118118
{
119119
return tools
120-
.Select(x => new Tool
120+
.Select(x => new OneOf<Tool, BashTool20250124, TextEditor20250124>(new Tool
121121
{
122122
Description = x.Description ?? string.Empty,
123123
Name = x.Name ?? string.Empty,
124124
InputSchema = x.Parameters ?? new InputSchema(),
125-
})
125+
}))
126126
.ToList();
127127
}
128128
}

src/libs/Anthropic/Generated/Anthropic.Models.BetaInputMessage.Json.g.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Anthropic
44
{
5-
public partial class BetaInputMessage
5+
public sealed partial class BetaInputMessage
66
{
77
/// <summary>
88
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
@@ -12,7 +12,7 @@ public string ToJson(
1212
{
1313
return global::System.Text.Json.JsonSerializer.Serialize(
1414
this,
15-
typeof(BetaInputMessage),
15+
this.GetType(),
1616
jsonSerializerContext);
1717
}
1818

@@ -28,22 +28,20 @@ public string ToJson(
2828
{
2929
return global::System.Text.Json.JsonSerializer.Serialize(
3030
this,
31-
typeof(BetaInputMessage),
3231
jsonSerializerOptions);
3332
}
3433

3534
/// <summary>
3635
/// Deserializes a JSON string using the provided JsonSerializerContext.
3736
/// </summary>
38-
public static T? FromJson<T>(
37+
public static global::Anthropic.BetaInputMessage? FromJson(
3938
string json,
4039
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
41-
where T : BetaInputMessage
4240
{
4341
return global::System.Text.Json.JsonSerializer.Deserialize(
4442
json,
45-
typeof(BetaInputMessage),
46-
jsonSerializerContext) as T;
43+
typeof(global::Anthropic.BetaInputMessage),
44+
jsonSerializerContext) as global::Anthropic.BetaInputMessage;
4745
}
4846

4947
/// <summary>
@@ -53,28 +51,26 @@ public string ToJson(
5351
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
5452
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
5553
#endif
56-
public static T? FromJson<T>(
54+
public static global::Anthropic.BetaInputMessage? FromJson(
5755
string json,
5856
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
59-
where T : BetaInputMessage
6057
{
61-
return global::System.Text.Json.JsonSerializer.Deserialize<BetaInputMessage>(
58+
return global::System.Text.Json.JsonSerializer.Deserialize<global::Anthropic.BetaInputMessage>(
6259
json,
63-
jsonSerializerOptions) as T;
60+
jsonSerializerOptions);
6461
}
6562

6663
/// <summary>
6764
/// Deserializes a JSON stream using the provided JsonSerializerContext.
6865
/// </summary>
69-
public static async global::System.Threading.Tasks.ValueTask<T?> FromJsonStreamAsync<T>(
66+
public static async global::System.Threading.Tasks.ValueTask<global::Anthropic.BetaInputMessage?> FromJsonStreamAsync(
7067
global::System.IO.Stream jsonStream,
7168
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
72-
where T : BetaInputMessage
7369
{
7470
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
7571
jsonStream,
76-
typeof(BetaInputMessage),
77-
jsonSerializerContext).ConfigureAwait(false)) as T;
72+
typeof(global::Anthropic.BetaInputMessage),
73+
jsonSerializerContext).ConfigureAwait(false)) as global::Anthropic.BetaInputMessage;
7874
}
7975

8076
/// <summary>
@@ -84,14 +80,13 @@ public string ToJson(
8480
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
8581
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
8682
#endif
87-
public static async global::System.Threading.Tasks.ValueTask<T?> FromJsonStreamAsync<T>(
83+
public static global::System.Threading.Tasks.ValueTask<global::Anthropic.BetaInputMessage?> FromJsonStreamAsync(
8884
global::System.IO.Stream jsonStream,
8985
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
90-
where T : BetaInputMessage
9186
{
92-
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync<BetaInputMessage?>(
87+
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::Anthropic.BetaInputMessage?>(
9388
jsonStream,
94-
jsonSerializerOptions).ConfigureAwait(false)) as T;
89+
jsonSerializerOptions);
9590
}
9691
}
9792
}

src/libs/Anthropic/Generated/Anthropic.Models.BetaInputMessage.g.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ namespace Anthropic
88
/// <summary>
99
///
1010
/// </summary>
11-
[global::System.Text.Json.Serialization.JsonPolymorphic(
12-
TypeDiscriminatorPropertyName = "role",
13-
IgnoreUnrecognizedTypeDiscriminators = true,
14-
UnknownDerivedTypeHandling = global::System.Text.Json.Serialization.JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
15-
public partial class BetaInputMessage
11+
public sealed partial class BetaInputMessage
1612
{
13+
/// <summary>
14+
///
15+
/// </summary>
16+
[global::System.Text.Json.Serialization.JsonPropertyName("role")]
17+
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::Anthropic.JsonConverters.BetaInputMessageRoleJsonConverter))]
18+
[global::System.Text.Json.Serialization.JsonRequired]
19+
public required global::Anthropic.BetaInputMessageRole Role { get; set; }
20+
1721
/// <summary>
1822
///
1923
/// </summary>
@@ -31,13 +35,16 @@ public partial class BetaInputMessage
3135
/// <summary>
3236
/// Initializes a new instance of the <see cref="BetaInputMessage" /> class.
3337
/// </summary>
38+
/// <param name="role"></param>
3439
/// <param name="content"></param>
3540
#if NET7_0_OR_GREATER
3641
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
3742
#endif
3843
public BetaInputMessage(
44+
global::Anthropic.BetaInputMessageRole role,
3945
global::Anthropic.AnyOf<string, global::System.Collections.Generic.IList<global::Anthropic.BetaInputContentBlock>> content)
4046
{
47+
this.Role = role;
4148
this.Content = content;
4249
}
4350

src/libs/Anthropic/Generated/Anthropic.Models.BetaInputMessageDiscriminator.Json.g.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/libs/Anthropic/Generated/Anthropic.Models.BetaInputMessageDiscriminator.g.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)