|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +#nullable disable |
| 5 | + |
| 6 | +using System; |
| 7 | +using System.Text.Json; |
| 8 | +using System.Text.Json.Serialization; |
| 9 | + |
| 10 | +namespace Azure.AI.Agents.Persistent |
| 11 | +{ |
| 12 | + /// <summary> Available tool types for agents named tools. </summary> |
| 13 | + [JsonConverter(typeof(PersistentAgentsNamedToolChoiceTypeConverter))] |
| 14 | + public readonly partial struct PersistentAgentsNamedToolChoiceType |
| 15 | + { |
| 16 | + } |
| 17 | + |
| 18 | + /// <summary> |
| 19 | + /// Custom JSON converter for PersistentAgentsNamedToolChoiceType. |
| 20 | + /// </summary> |
| 21 | + internal class PersistentAgentsNamedToolChoiceTypeConverter : JsonConverter<PersistentAgentsNamedToolChoiceType> |
| 22 | + { |
| 23 | + /// <summary> |
| 24 | + /// Reads and converts the JSON to PersistentAgentsNamedToolChoiceType. |
| 25 | + /// </summary> |
| 26 | + /// <param name="reader">The reader.</param> |
| 27 | + /// <param name="typeToConvert">The type to convert.</param> |
| 28 | + /// <param name="options">An object that specifies serialization options to use.</param> |
| 29 | + /// <returns>The converted value.</returns> |
| 30 | + public override PersistentAgentsNamedToolChoiceType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 31 | + { |
| 32 | + if (reader.TokenType == JsonTokenType.Null) |
| 33 | + { |
| 34 | + throw new JsonException("Cannot convert null value to PersistentAgentsNamedToolChoiceType."); |
| 35 | + } |
| 36 | + |
| 37 | + if (reader.TokenType != JsonTokenType.String) |
| 38 | + { |
| 39 | + throw new JsonException($"Cannot convert token type {reader.TokenType} to PersistentAgentsNamedToolChoiceType."); |
| 40 | + } |
| 41 | + |
| 42 | + string value = reader.GetString(); |
| 43 | + return new PersistentAgentsNamedToolChoiceType(value); |
| 44 | + } |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Writes a PersistentAgentsNamedToolChoiceType as JSON. |
| 48 | + /// </summary> |
| 49 | + /// <param name="writer">The writer to write to.</param> |
| 50 | + /// <param name="value">The value to convert to JSON.</param> |
| 51 | + /// <param name="options">An object that specifies serialization options to use.</param> |
| 52 | + public override void Write(Utf8JsonWriter writer, PersistentAgentsNamedToolChoiceType value, JsonSerializerOptions options) |
| 53 | + { |
| 54 | + if (writer == null) |
| 55 | + { |
| 56 | + throw new ArgumentNullException(nameof(writer)); |
| 57 | + } |
| 58 | + |
| 59 | + writer.WriteStringValue(value.ToString()); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments