diff --git a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.Serialization.cs b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.Serialization.cs deleted file mode 100644 index 3e84b77f907b..000000000000 --- a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.Serialization.cs +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.AI.Agents.Persistent -{ - internal partial class File : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(File)} does not support writing '{format}' format."); - } - - if (Optional.IsDefined(ContentType)) - { - writer.WritePropertyName("contentType"u8); - writer.WriteStringValue(ContentType); - } - if (Optional.IsDefined(Filename)) - { - writer.WritePropertyName("filename"u8); - writer.WriteStringValue(Filename); - } - writer.WritePropertyName("contents"u8); - writer.WriteBase64StringValue(Contents.ToArray(), "D"); - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - File IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(File)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeFile(document.RootElement, options); - } - - internal static File DeserializeFile(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string contentType = default; - string filename = default; - BinaryData contents = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("contentType"u8)) - { - contentType = property.Value.GetString(); - continue; - } - if (property.NameEquals("filename"u8)) - { - filename = property.Value.GetString(); - continue; - } - if (property.NameEquals("contents"u8)) - { - contents = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new File(contentType, filename, contents, serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options, AzureAIAgentsPersistentContext.Default); - default: - throw new FormatException($"The model {nameof(File)} does not support writing '{options.Format}' format."); - } - } - - File IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeFile(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(File)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - /// Deserializes the model from a raw response. - /// The response to deserialize the model from. - internal static File FromResponse(Response response) - { - using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeFile(document.RootElement); - } - - /// Convert into a . - internal virtual RequestContent ToRequestContent() - { - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); - return content; - } - } -} diff --git a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.cs b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.cs deleted file mode 100644 index fe6fa90e5f73..000000000000 --- a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/File.cs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.Agents.Persistent -{ - /// - /// A file in an HTTP request, response, or multipart payload. - /// - /// Files have a special meaning that the HTTP library understands. When the body of an HTTP request, response, - /// or multipart payload is _effectively_ an instance of `TypeSpec.Http.File` or any type that extends it, the - /// operation is treated as a file upload or download. - /// - /// When using file bodies, the fields of the file model are defined to come from particular locations by default: - /// - /// - `contentType`: The `Content-Type` header of the request, response, or multipart payload (CANNOT be overridden or changed). - /// - `contents`: The body of the request, response, or multipart payload (CANNOT be overridden or changed). - /// - `filename`: The `filename` parameter value of the `Content-Disposition` header of the response or multipart payload - /// (MAY be overridden or changed). - /// - /// A File may be used as a normal structured JSON object in a request or response, if the request specifies an explicit - /// `Content-Type` header. In this case, the entire File model is serialized as if it were any other model. In a JSON payload, - /// it will have a structure like: - /// - /// ``` - /// { - /// "contentType": <string?>, - /// "filename": <string?>, - /// "contents": <string, base64> - /// } - /// ``` - /// - /// The `contentType` _within_ the file defines what media types the data inside the file can be, but if the specification - /// defines a `Content-Type` for the payload as HTTP metadata, that `Content-Type` metadata defines _how the file is - /// serialized_. See the examples below for more information. - /// - /// NOTE: The `filename` and `contentType` fields are optional. Furthermore, the default location of `filename` - /// (`Content-Disposition: <disposition>; filename=<filename>`) is only valid in HTTP responses and multipart payloads. If - /// you wish to send the `filename` in a request, you must use HTTP metadata decorators to describe the location of the - /// `filename` field. You can combine the metadata decorators with `@visibility` to control when the `filename` location - /// is overridden, as shown in the examples below. - /// - internal partial class File - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// - /// The contents of the file. - /// - /// In file bodies, this value comes from the body of the request, response, or multipart payload. In JSON bodies, - /// this value is serialized as a field in the response. - /// - /// is null. - public File(BinaryData contents) - { - Argument.AssertNotNull(contents, nameof(contents)); - - Contents = contents; - } - - /// Initializes a new instance of . - /// - /// The allowed media (MIME) types of the file contents. - /// - /// In file bodies, this value comes from the `Content-Type` header of the request or response. In JSON bodies, - /// this value is serialized as a field in the response. - /// - /// NOTE: this is not _necessarily_ the same as the `Content-Type` header of the request or response, but - /// it will be for file bodies. It may be different if the file is serialized as a JSON object. It always refers to the - /// _contents_ of the file, and not necessarily the way the file itself is transmitted or serialized. - /// - /// - /// The name of the file, if any. - /// - /// In file bodies, this value comes from the `filename` parameter of the `Content-Disposition` header of the response - /// or multipart payload. In JSON bodies, this value is serialized as a field in the response. - /// - /// NOTE: By default, `filename` cannot be sent in request payloads and can only be sent in responses and multipart - /// payloads, as the `Content-Disposition` header is not valid in requests. If you want to send the `filename` in a request, - /// you must extend the `File` model and override the `filename` property with a different location defined by HTTP metadata - /// decorators. - /// - /// - /// The contents of the file. - /// - /// In file bodies, this value comes from the body of the request, response, or multipart payload. In JSON bodies, - /// this value is serialized as a field in the response. - /// - /// Keeps track of any properties unknown to the library. - internal File(string contentType, string filename, BinaryData contents, IDictionary serializedAdditionalRawData) - { - ContentType = contentType; - Filename = filename; - Contents = contents; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal File() - { - } - - /// - /// The allowed media (MIME) types of the file contents. - /// - /// In file bodies, this value comes from the `Content-Type` header of the request or response. In JSON bodies, - /// this value is serialized as a field in the response. - /// - /// NOTE: this is not _necessarily_ the same as the `Content-Type` header of the request or response, but - /// it will be for file bodies. It may be different if the file is serialized as a JSON object. It always refers to the - /// _contents_ of the file, and not necessarily the way the file itself is transmitted or serialized. - /// - public string ContentType { get; set; } - /// - /// The name of the file, if any. - /// - /// In file bodies, this value comes from the `filename` parameter of the `Content-Disposition` header of the response - /// or multipart payload. In JSON bodies, this value is serialized as a field in the response. - /// - /// NOTE: By default, `filename` cannot be sent in request payloads and can only be sent in responses and multipart - /// payloads, as the `Content-Disposition` header is not valid in requests. If you want to send the `filename` in a request, - /// you must extend the `File` model and override the `filename` property with a different location defined by HTTP metadata - /// decorators. - /// - public string Filename { get; set; } - /// - /// The contents of the file. - /// - /// In file bodies, this value comes from the body of the request, response, or multipart payload. In JSON bodies, - /// this value is serialized as a field in the response. - /// - /// To assign a byte[] to this property use . - /// The byte[] will be serialized to a Base64 encoded string. - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromBytes(new byte[] { 1, 2, 3 }) - /// Creates a payload of "AQID". - /// - /// - /// - /// - public BinaryData Contents { get; } - } -} diff --git a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/PersistentAgentsAdministrationClientOptions.cs b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/PersistentAgentsAdministrationClientOptions.cs index 9cb1de8e0318..41280307fd81 100644 --- a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/PersistentAgentsAdministrationClientOptions.cs +++ b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/PersistentAgentsAdministrationClientOptions.cs @@ -13,15 +13,15 @@ namespace Azure.AI.Agents.Persistent /// Client options for PersistentAgentsAdministrationClient. public partial class PersistentAgentsAdministrationClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V1; + private const ServiceVersion LatestVersion = ServiceVersion.V2025_05_15_Preview; /// The version of the service to use. public enum ServiceVersion { /// Service version "2025-05-01". V2025_05_01 = 1, - /// Service version "v1". - V1 = 2, + /// Service version "2025-05-15-preview". + V2025_05_15_Preview = 2, } internal string Version { get; } @@ -32,7 +32,7 @@ public PersistentAgentsAdministrationClientOptions(ServiceVersion version = Late Version = version switch { ServiceVersion.V2025_05_01 => "2025-05-01", - ServiceVersion.V1 => "v1", + ServiceVersion.V2025_05_15_Preview => "2025-05-15-preview", _ => throw new NotSupportedException() }; } diff --git a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.Serialization.cs b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.Serialization.cs index 630757d555d5..556457d136fb 100644 --- a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.Serialization.cs +++ b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.Serialization.cs @@ -36,7 +36,14 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WritePropertyName("file"u8); - writer.WriteObjectValue(Data, options); +#if NET6_0_OR_GREATER + writer.WriteRawValue(global::System.BinaryData.FromStream(Data)); +#else + using (JsonDocument document = JsonDocument.Parse(BinaryData.FromStream(Data), ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif writer.WritePropertyName("purpose"u8); writer.WriteStringValue(Purpose.ToString()); if (Optional.IsDefined(Filename)) @@ -81,7 +88,7 @@ internal static UploadFileRequest DeserializeUploadFileRequest(JsonElement eleme { return null; } - File file = default; + Stream file = default; PersistentAgentFilePurpose purpose = default; string filename = default; IDictionary serializedAdditionalRawData = default; @@ -90,7 +97,7 @@ internal static UploadFileRequest DeserializeUploadFileRequest(JsonElement eleme { if (property.NameEquals("file"u8)) { - file = File.DeserializeFile(property.Value, options); + file = BinaryData.FromString(property.Value.GetRawText()).ToStream(); continue; } if (property.NameEquals("purpose"u8)) diff --git a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.cs b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.cs index de3f5be1f220..8237de65309a 100644 --- a/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.cs +++ b/sdk/ai/Azure.AI.Agents.Persistent/src/Generated/UploadFileRequest.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.IO; namespace Azure.AI.Agents.Persistent { @@ -49,7 +50,7 @@ internal partial class UploadFileRequest /// The file data, in bytes. /// The intended purpose of the uploaded file. Use `assistants` for Agents and Message files, `vision` for Agents image file inputs, `batch` for Batch API, and `fine-tune` for Fine-tuning. /// is null. - public UploadFileRequest(File data, PersistentAgentFilePurpose purpose) + public UploadFileRequest(Stream data, PersistentAgentFilePurpose purpose) { Argument.AssertNotNull(data, nameof(data)); @@ -62,7 +63,7 @@ public UploadFileRequest(File data, PersistentAgentFilePurpose purpose) /// The intended purpose of the uploaded file. Use `assistants` for Agents and Message files, `vision` for Agents image file inputs, `batch` for Batch API, and `fine-tune` for Fine-tuning. /// The name of the file. /// Keeps track of any properties unknown to the library. - internal UploadFileRequest(File data, PersistentAgentFilePurpose purpose, string filename, IDictionary serializedAdditionalRawData) + internal UploadFileRequest(Stream data, PersistentAgentFilePurpose purpose, string filename, IDictionary serializedAdditionalRawData) { Data = data; Purpose = purpose; @@ -76,7 +77,7 @@ internal UploadFileRequest() } /// The file data, in bytes. - public File Data { get; } + public Stream Data { get; } /// The intended purpose of the uploaded file. Use `assistants` for Agents and Message files, `vision` for Agents image file inputs, `batch` for Batch API, and `fine-tune` for Fine-tuning. public PersistentAgentFilePurpose Purpose { get; } /// The name of the file. diff --git a/sdk/ai/Azure.AI.Agents.Persistent/tsp-location.yaml b/sdk/ai/Azure.AI.Agents.Persistent/tsp-location.yaml index 35e2e6045ef4..09751edba0a5 100644 --- a/sdk/ai/Azure.AI.Agents.Persistent/tsp-location.yaml +++ b/sdk/ai/Azure.AI.Agents.Persistent/tsp-location.yaml @@ -1,4 +1,4 @@ directory: specification/ai/Azure.AI.Agents -commit: 6625eb323d07755a1d77c17dc713e484d3c1e00e +commit: 71c47227c4af124c945a77a89748eaf8baf84b8c repo: Azure/azure-rest-api-specs additionalDirectories: