Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ namespace Microsoft.Extensions.AI;
// [JsonDerivedType(typeof(FunctionApprovalResponseContent), typeDiscriminator: "functionApprovalResponse")]
// [JsonDerivedType(typeof(McpServerToolCallContent), typeDiscriminator: "mcpServerToolCall")]
// [JsonDerivedType(typeof(McpServerToolResultContent), typeDiscriminator: "mcpServerToolResult")]
// [JsonDerivedType(typeof(McpServerToolApprovalRequestContent), typeDiscriminator: "mcpServerToolApprovalRequest")]
// [JsonDerivedType(typeof(McpServerToolApprovalResponseContent), typeDiscriminator: "mcpServerToolApprovalResponse")]
// [JsonDerivedType(typeof(CodeInterpreterToolCallContent), typeDiscriminator: "codeInterpreterToolCall")]
// [JsonDerivedType(typeof(CodeInterpreterToolResultContent), typeDiscriminator: "codeInterpreterToolResult")]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Microsoft.Extensions.AI;

/// <summary>
/// Represents a request for user approval of a function call.
/// Represents a request for user approval of a call content.
/// </summary>
[Experimental("MEAI001")]
public sealed class FunctionApprovalRequestContent : UserInputRequestContent
Expand All @@ -17,25 +17,25 @@ public sealed class FunctionApprovalRequestContent : UserInputRequestContent
/// Initializes a new instance of the <see cref="FunctionApprovalRequestContent"/> class.
/// </summary>
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param>
/// <param name="functionCall">The function call that requires user approval.</param>
/// <param name="callContent">The call content that requires user approval.</param>
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception>
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception>
public FunctionApprovalRequestContent(string id, FunctionCallContent functionCall)
/// <exception cref="ArgumentNullException"><paramref name="callContent"/> is <see langword="null"/>.</exception>
public FunctionApprovalRequestContent(string id, AIContent callContent)
: base(id)
{
FunctionCall = Throw.IfNull(functionCall);
CallContent = Throw.IfNull(callContent);
}

/// <summary>
/// Gets the function call that pre-invoke approval is required for.
/// Gets the call content that pre-invoke approval is required for.
/// </summary>
public FunctionCallContent FunctionCall { get; }
public AIContent CallContent { get; }

/// <summary>
/// Creates a <see cref="FunctionApprovalResponseContent"/> to indicate whether the function call is approved or rejected based on the value of <paramref name="approved"/>.
/// Creates a <see cref="FunctionApprovalResponseContent"/> to indicate whether the call is approved or rejected based on the value of <paramref name="approved"/>.
/// </summary>
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param>
/// <param name="approved"><see langword="true"/> if the call is approved; otherwise, <see langword="false"/>.</param>
/// <returns>The <see cref="FunctionApprovalResponseContent"/> representing the approval response.</returns>
public FunctionApprovalResponseContent CreateResponse(bool approved) => new(Id, approved, FunctionCall);
public FunctionApprovalResponseContent CreateResponse(bool approved) => new(Id, approved, CallContent);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
namespace Microsoft.Extensions.AI;

/// <summary>
/// Represents a response to a function approval request.
/// Represents a response to an approval request.
/// </summary>
[Experimental("MEAI001")]
public sealed class FunctionApprovalResponseContent : UserInputResponseContent
{
/// <summary>
/// Initializes a new instance of the <see cref="FunctionApprovalResponseContent"/> class.
/// </summary>
/// <param name="id">The ID that uniquely identifies the function approval request/response pair.</param>
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param>
/// <param name="functionCall">The function call that requires user approval.</param>
/// <param name="id">The ID that uniquely identifies the approval request/response pair.</param>
/// <param name="approved"><see langword="true"/> if the call is approved; otherwise, <see langword="false"/>.</param>
/// <param name="callContent">The call content that requires user approval.</param>
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="id"/> is empty or composed entirely of whitespace.</exception>
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception>
public FunctionApprovalResponseContent(string id, bool approved, FunctionCallContent functionCall)
/// <exception cref="ArgumentNullException"><paramref name="callContent"/> is <see langword="null"/>.</exception>
public FunctionApprovalResponseContent(string id, bool approved, AIContent callContent)
: base(id)
{
Approved = approved;
FunctionCall = Throw.IfNull(functionCall);
CallContent = Throw.IfNull(callContent);
}

/// <summary>
Expand All @@ -35,7 +35,7 @@ public FunctionApprovalResponseContent(string id, bool approved, FunctionCallCon
public bool Approved { get; }

/// <summary>
/// Gets the function call for which approval was requested.
/// Gets the call content for which approval was requested.
/// </summary>
public FunctionCallContent FunctionCall { get; }
public AIContent CallContent { get; }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.Extensions.AI;
[Experimental("MEAI001")]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(FunctionApprovalRequestContent), "functionApprovalRequest")]
[JsonDerivedType(typeof(McpServerToolApprovalRequestContent), "mcpServerToolApprovalRequest")]
public class UserInputRequestContent : AIContent
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.Extensions.AI;
[Experimental("MEAI001")]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type")]
[JsonDerivedType(typeof(FunctionApprovalResponseContent), "functionApprovalResponse")]
[JsonDerivedType(typeof(McpServerToolApprovalResponseContent), "mcpServerToolApprovalResponse")]
public class UserInputResponseContent : AIContent
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ private static JsonSerializerOptions CreateDefaultOptions()
AddAIContentType(options, typeof(FunctionApprovalResponseContent), typeDiscriminatorId: "functionApprovalResponse", checkBuiltIn: false);
AddAIContentType(options, typeof(McpServerToolCallContent), typeDiscriminatorId: "mcpServerToolCall", checkBuiltIn: false);
AddAIContentType(options, typeof(McpServerToolResultContent), typeDiscriminatorId: "mcpServerToolResult", checkBuiltIn: false);
AddAIContentType(options, typeof(McpServerToolApprovalRequestContent), typeDiscriminatorId: "mcpServerToolApprovalRequest", checkBuiltIn: false);
AddAIContentType(options, typeof(McpServerToolApprovalResponseContent), typeDiscriminatorId: "mcpServerToolApprovalResponse", checkBuiltIn: false);
AddAIContentType(options, typeof(CodeInterpreterToolCallContent), typeDiscriminatorId: "codeInterpreterToolCall", checkBuiltIn: false);
AddAIContentType(options, typeof(CodeInterpreterToolResultContent), typeDiscriminatorId: "codeInterpreterToolResult", checkBuiltIn: false);

Expand Down Expand Up @@ -129,8 +127,6 @@ private static JsonSerializerOptions CreateDefaultOptions()
[JsonSerializable(typeof(FunctionApprovalResponseContent))]
[JsonSerializable(typeof(McpServerToolCallContent))]
[JsonSerializable(typeof(McpServerToolResultContent))]
[JsonSerializable(typeof(McpServerToolApprovalRequestContent))]
[JsonSerializable(typeof(McpServerToolApprovalResponseContent))]
[JsonSerializable(typeof(CodeInterpreterToolCallContent))]
[JsonSerializable(typeof(CodeInterpreterToolResultContent))]
[JsonSerializable(typeof(ResponseContinuationToken))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ internal static IEnumerable<ChatMessage> ToChatMessages(IEnumerable<ResponseItem
break;

case McpToolCallApprovalRequestItem mtcari:
message.Contents.Add(new McpServerToolApprovalRequestContent(mtcari.Id, new(mtcari.Id, mtcari.ToolName, mtcari.ServerLabel)
message.Contents.Add(new FunctionApprovalRequestContent(mtcari.Id, new McpServerToolCallContent(mtcari.Id, mtcari.ToolName, mtcari.ServerLabel)
{
Arguments = JsonSerializer.Deserialize(mtcari.ToolArguments.ToMemory().Span, OpenAIJsonContext.Default.IReadOnlyDictionaryStringObject)!,
RawRepresentation = mtcari,
Expand All @@ -222,10 +222,6 @@ internal static IEnumerable<ChatMessage> ToChatMessages(IEnumerable<ResponseItem
});
break;

case McpToolCallApprovalResponseItem mtcari:
message.Contents.Add(new McpServerToolApprovalResponseContent(mtcari.ApprovalRequestId, mtcari.Approved) { RawRepresentation = mtcari });
break;

case CodeInterpreterCallResponseItem cicri:
AddCodeInterpreterContents(cicri, message.Contents);
break;
Expand Down Expand Up @@ -422,7 +418,7 @@ ChatResponseUpdate CreateUpdate(AIContent? content = null) =>
break;

case McpToolCallApprovalRequestItem mtcari:
yield return CreateUpdate(new McpServerToolApprovalRequestContent(mtcari.Id, new(mtcari.Id, mtcari.ToolName, mtcari.ServerLabel)
yield return CreateUpdate(new FunctionApprovalRequestContent(mtcari.Id, new McpServerToolCallContent(mtcari.Id, mtcari.ToolName, mtcari.ServerLabel)
{
Arguments = JsonSerializer.Deserialize(mtcari.ToolArguments.ToMemory().Span, OpenAIJsonContext.Default.IReadOnlyDictionaryStringObject)!,
RawRepresentation = mtcari,
Expand Down Expand Up @@ -855,7 +851,7 @@ internal static IEnumerable<ResponseItem> ToOpenAIResponseItems(IEnumerable<Chat
ResponseItem? directItem = item switch
{
{ RawRepresentation: ResponseItem rawRep } => rawRep,
McpServerToolApprovalResponseContent mcpResp => ResponseItem.CreateMcpApprovalResponseItem(mcpResp.Id, mcpResp.Approved),
FunctionApprovalResponseContent { CallContent: McpServerToolCallContent mcpCall } farc => ResponseItem.CreateMcpApprovalResponseItem(mcpCall.CallId, farc.Approved),
_ => null
};

Expand Down Expand Up @@ -1052,8 +1048,8 @@ static FunctionCallOutputResponseItem SerializeAIContent(string callId, IEnumera
}
break;

case McpServerToolApprovalResponseContent mcpApprovalResponseContent:
yield return ResponseItem.CreateMcpApprovalResponseItem(mcpApprovalResponseContent.Id, mcpApprovalResponseContent.Approved);
case FunctionApprovalResponseContent { CallContent: McpServerToolCallContent mcpCall } farc:
yield return ResponseItem.CreateMcpApprovalResponseItem(mcpCall.CallId, farc.Approved);
break;
}
}
Expand Down Expand Up @@ -1090,12 +1086,12 @@ static FunctionCallOutputResponseItem SerializeAIContent(string callId, IEnumera
AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object?>)))));
break;

case McpServerToolApprovalRequestContent mcpApprovalRequestContent:
case FunctionApprovalRequestContent { CallContent: McpServerToolCallContent mcpCall }:
yield return ResponseItem.CreateMcpApprovalRequestItem(
mcpApprovalRequestContent.Id,
mcpApprovalRequestContent.ToolCall.ServerName,
mcpApprovalRequestContent.ToolCall.ToolName,
BinaryData.FromBytes(JsonSerializer.SerializeToUtf8Bytes(mcpApprovalRequestContent.ToolCall.Arguments!, OpenAIJsonContext.Default.IReadOnlyDictionaryStringObject)));
mcpCall.CallId,
mcpCall.ServerName,
mcpCall.ToolName,
BinaryData.FromBytes(JsonSerializer.SerializeToUtf8Bytes(mcpCall.Arguments!, OpenAIJsonContext.Default.IReadOnlyDictionaryStringObject)));
break;

case McpServerToolCallContent mstcc:
Expand Down
Loading
Loading