Skip to content

Commit 04ceb38

Browse files
committed
Squashed approach from dotnet#7245
1 parent 9974fbf commit 04ceb38

48 files changed

Lines changed: 2104 additions & 918 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Libraries/Microsoft.Extensions.AI.Abstractions/CompatibilitySuppressions.xml

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIContent.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ namespace Microsoft.Extensions.AI;
1818
[JsonDerivedType(typeof(TextReasoningContent), typeDiscriminator: "reasoning")]
1919
[JsonDerivedType(typeof(UriContent), typeDiscriminator: "uri")]
2020
[JsonDerivedType(typeof(UsageContent), typeDiscriminator: "usage")]
21+
[JsonDerivedType(typeof(FunctionApprovalRequestContent), typeDiscriminator: "functionApprovalRequest")]
22+
[JsonDerivedType(typeof(FunctionApprovalResponseContent), typeDiscriminator: "functionApprovalResponse")]
23+
[JsonDerivedType(typeof(McpServerToolCallContent), typeDiscriminator: "mcpServerToolCall")]
24+
[JsonDerivedType(typeof(McpServerToolResultContent), typeDiscriminator: "mcpServerToolResult")]
2125

2226
// These should be added in once they're no longer [Experimental]. If they're included while still
2327
// experimental, any JsonSerializerContext that includes AIContent will incur errors about using
2428
// experimental types in its source generated files. When [Experimental] is removed from these types,
2529
// these lines should be uncommented and the corresponding lines in AIJsonUtilities.CreateDefaultOptions
2630
// as well as the [JsonSerializable] attributes for them on the JsonContext should be removed.
27-
// [JsonDerivedType(typeof(FunctionApprovalRequestContent), typeDiscriminator: "functionApprovalRequest")]
28-
// [JsonDerivedType(typeof(FunctionApprovalResponseContent), typeDiscriminator: "functionApprovalResponse")]
29-
// [JsonDerivedType(typeof(McpServerToolCallContent), typeDiscriminator: "mcpServerToolCall")]
30-
// [JsonDerivedType(typeof(McpServerToolResultContent), typeDiscriminator: "mcpServerToolResult")]
31-
// [JsonDerivedType(typeof(McpServerToolApprovalRequestContent), typeDiscriminator: "mcpServerToolApprovalRequest")]
32-
// [JsonDerivedType(typeof(McpServerToolApprovalResponseContent), typeDiscriminator: "mcpServerToolApprovalResponse")]
3331
// [JsonDerivedType(typeof(CodeInterpreterToolCallContent), typeDiscriminator: "codeInterpreterToolCall")]
3432
// [JsonDerivedType(typeof(CodeInterpreterToolResultContent), typeDiscriminator: "codeInterpreterToolResult")]
3533

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalRequestContent.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,39 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Diagnostics.CodeAnalysis;
6-
using Microsoft.Shared.DiagnosticIds;
75
using Microsoft.Shared.Diagnostics;
86

97
namespace Microsoft.Extensions.AI;
108

119
/// <summary>
12-
/// Represents a request for user approval of a function call.
10+
/// Represents a request for approval before invoking a function call.
1311
/// </summary>
14-
[Experimental(DiagnosticIds.Experiments.AIFunctionApprovals, UrlFormat = DiagnosticIds.UrlFormat)]
15-
public sealed class FunctionApprovalRequestContent : UserInputRequestContent
12+
public sealed class FunctionApprovalRequestContent : InputRequestContent
1613
{
1714
/// <summary>
1815
/// Initializes a new instance of the <see cref="FunctionApprovalRequestContent"/> class.
1916
/// </summary>
20-
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param>
21-
/// <param name="functionCall">The function call that requires user approval.</param>
22-
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception>
23-
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception>
17+
/// <param name="requestId">The unique identifier that correlates this request with its corresponding response. This may differ from the <see cref="FunctionCallContent.CallId"/> of the specified <paramref name="functionCall"/>.</param>
18+
/// <param name="functionCall">The function call that requires approval before execution.</param>
19+
/// <exception cref="ArgumentNullException"><paramref name="requestId"/> is <see langword="null"/>.</exception>
20+
/// <exception cref="ArgumentException"><paramref name="requestId"/> is empty or composed entirely of whitespace.</exception>
2421
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception>
25-
public FunctionApprovalRequestContent(string id, FunctionCallContent functionCall)
26-
: base(id)
22+
public FunctionApprovalRequestContent(string requestId, FunctionCallContent functionCall)
23+
: base(requestId)
2724
{
2825
FunctionCall = Throw.IfNull(functionCall);
2926
}
3027

3128
/// <summary>
32-
/// Gets the function call that pre-invoke approval is required for.
29+
/// Gets the function call that requires approval before execution.
3330
/// </summary>
3431
public FunctionCallContent FunctionCall { get; }
3532

3633
/// <summary>
37-
/// Creates a <see cref="FunctionApprovalResponseContent"/> to indicate whether the function call is approved or rejected based on the value of <paramref name="approved"/>.
34+
/// Creates a <see cref="FunctionApprovalResponseContent"/> indicating whether the function call is approved or rejected.
3835
/// </summary>
3936
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param>
4037
/// <param name="reason">An optional reason for the approval or rejection.</param>
41-
/// <returns>The <see cref="FunctionApprovalResponseContent"/> representing the approval response.</returns>
42-
public FunctionApprovalResponseContent CreateResponse(bool approved, string? reason = null) => new(Id, approved, FunctionCall) { Reason = reason };
38+
/// <returns>The <see cref="FunctionApprovalResponseContent"/> correlated with this request.</returns>
39+
public FunctionApprovalResponseContent CreateResponse(bool approved, string? reason = null) => new(RequestId, approved, FunctionCall) { Reason = reason };
4340
}

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalResponseContent.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,38 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Diagnostics.CodeAnalysis;
6-
using Microsoft.Shared.DiagnosticIds;
75
using Microsoft.Shared.Diagnostics;
86

97
namespace Microsoft.Extensions.AI;
108

119
/// <summary>
12-
/// Represents a response to a function approval request.
10+
/// Represents a response to a <see cref="FunctionApprovalRequestContent"/>, indicating whether the function call was approved.
1311
/// </summary>
14-
[Experimental(DiagnosticIds.Experiments.AIFunctionApprovals, UrlFormat = DiagnosticIds.UrlFormat)]
15-
public sealed class FunctionApprovalResponseContent : UserInputResponseContent
12+
public sealed class FunctionApprovalResponseContent : InputResponseContent
1613
{
1714
/// <summary>
1815
/// Initializes a new instance of the <see cref="FunctionApprovalResponseContent"/> class.
1916
/// </summary>
20-
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param>
17+
/// <param name="requestId">The unique identifier of the <see cref="FunctionApprovalRequestContent"/> associated with this response.</param>
2118
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param>
22-
/// <param name="functionCall">The function call that requires user approval.</param>
23-
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception>
24-
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception>
19+
/// <param name="functionCall">The function call that was subject to approval.</param>
20+
/// <exception cref="ArgumentNullException"><paramref name="requestId"/> is <see langword="null"/>.</exception>
21+
/// <exception cref="ArgumentException"><paramref name="requestId"/> is empty or composed entirely of whitespace.</exception>
2522
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception>
26-
public FunctionApprovalResponseContent(string id, bool approved, FunctionCallContent functionCall)
27-
: base(id)
23+
public FunctionApprovalResponseContent(string requestId, bool approved, FunctionCallContent functionCall)
24+
: base(requestId)
2825
{
2926
Approved = approved;
3027
FunctionCall = Throw.IfNull(functionCall);
3128
}
3229

3330
/// <summary>
34-
/// Gets a value indicating whether the user approved the request.
31+
/// Gets a value indicating whether the function call was approved for execution.
3532
/// </summary>
3633
public bool Approved { get; }
3734

3835
/// <summary>
39-
/// Gets the function call for which approval was requested.
36+
/// Gets the function call that was subject to approval.
4037
/// </summary>
4138
public FunctionCallContent FunctionCall { get; }
4239

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Extensions.AI;
1414
/// Represents a function call request.
1515
/// </summary>
1616
[DebuggerDisplay("{DebuggerDisplay,nq}")]
17+
[JsonDerivedType(typeof(McpServerToolCallContent), "mcpServerToolCall")]
1718
public class FunctionCallContent : AIContent
1819
{
1920
/// <summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionResultContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Extensions.AI;
1313
/// Represents the result of a function call.
1414
/// </summary>
1515
[DebuggerDisplay("{DebuggerDisplay,nq}")]
16+
[JsonDerivedType(typeof(McpServerToolResultContent), "mcpServerToolResult")]
1617
public class FunctionResultContent : AIContent
1718
{
1819
/// <summary>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Text.Json.Serialization;
6+
using Microsoft.Shared.Diagnostics;
7+
8+
namespace Microsoft.Extensions.AI;
9+
10+
/// <summary>
11+
/// Represents a request for input from the user or application.
12+
/// </summary>
13+
[JsonDerivedType(typeof(FunctionApprovalRequestContent), "functionApprovalRequest")]
14+
public class InputRequestContent : AIContent
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="InputRequestContent"/> class.
18+
/// </summary>
19+
/// <param name="requestId">The unique identifier that correlates this request with its corresponding response.</param>
20+
/// <exception cref="ArgumentNullException"><paramref name="requestId"/> is <see langword="null"/>.</exception>
21+
/// <exception cref="ArgumentException"><paramref name="requestId"/> is empty or composed entirely of whitespace.</exception>
22+
protected InputRequestContent(string requestId)
23+
{
24+
RequestId = Throw.IfNullOrWhitespace(requestId);
25+
}
26+
27+
/// <summary>
28+
/// Gets the unique identifier that correlates this request with its corresponding <see cref="InputResponseContent"/>.
29+
/// </summary>
30+
public string RequestId { get; }
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Text.Json.Serialization;
6+
using Microsoft.Shared.Diagnostics;
7+
8+
namespace Microsoft.Extensions.AI;
9+
10+
/// <summary>
11+
/// Represents the response to an <see cref="InputRequestContent"/>.
12+
/// </summary>
13+
[JsonDerivedType(typeof(FunctionApprovalResponseContent), "functionApprovalResponse")]
14+
public class InputResponseContent : AIContent
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="InputResponseContent"/> class.
18+
/// </summary>
19+
/// <param name="requestId">The unique identifier that correlates this response with its corresponding request.</param>
20+
/// <exception cref="ArgumentNullException"><paramref name="requestId"/> is <see langword="null"/>.</exception>
21+
/// <exception cref="ArgumentException"><paramref name="requestId"/> is empty or composed entirely of whitespace.</exception>
22+
protected InputResponseContent(string requestId)
23+
{
24+
RequestId = Throw.IfNullOrWhitespace(requestId);
25+
}
26+
27+
/// <summary>
28+
/// Gets the unique identifier that correlates this response with its corresponding <see cref="InputRequestContent"/>.
29+
/// </summary>
30+
public string RequestId { get; }
31+
}

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolApprovalRequestContent.cs

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

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolApprovalResponseContent.cs

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

0 commit comments

Comments
 (0)