Add missing Title and Icons properties to ResourceLinkBlock (#1320)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
parent
d9ae6bc266
commit
54283a8590
1 changed files with 102 additions and 1 deletions
|
|
@ -90,11 +90,13 @@ public abstract class ContentBlock
|
|||
string? type = null;
|
||||
string? text = null;
|
||||
string? name = null;
|
||||
string? title = null;
|
||||
ReadOnlyMemory<byte>? data = null;
|
||||
string? mimeType = null;
|
||||
string? uri = null;
|
||||
string? description = null;
|
||||
long? size = null;
|
||||
IList<Icon>? icons = null;
|
||||
ResourceContents? resource = null;
|
||||
Annotations? annotations = null;
|
||||
JsonObject? meta = null;
|
||||
|
|
@ -130,6 +132,10 @@ public abstract class ContentBlock
|
|||
name = reader.GetString();
|
||||
break;
|
||||
|
||||
case "title":
|
||||
title = reader.GetString();
|
||||
break;
|
||||
|
||||
case "data":
|
||||
data = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan.ToArray();
|
||||
break;
|
||||
|
|
@ -150,6 +156,18 @@ public abstract class ContentBlock
|
|||
size = reader.GetInt64();
|
||||
break;
|
||||
|
||||
case "icons":
|
||||
if (reader.TokenType == JsonTokenType.StartArray)
|
||||
{
|
||||
icons = [];
|
||||
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
|
||||
{
|
||||
icons.Add(JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.Icon) ??
|
||||
throw new JsonException("Unexpected null item in icons array."));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "resource":
|
||||
resource = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.ResourceContents);
|
||||
break;
|
||||
|
|
@ -233,9 +251,11 @@ public abstract class ContentBlock
|
|||
{
|
||||
Uri = uri ?? throw new JsonException("URI must be provided for 'resource_link' type."),
|
||||
Name = name ?? throw new JsonException("Name must be provided for 'resource_link' type."),
|
||||
Title = title,
|
||||
Description = description,
|
||||
MimeType = mimeType,
|
||||
Size = size,
|
||||
Icons = icons,
|
||||
},
|
||||
|
||||
"tool_use" => new ToolUseContentBlock
|
||||
|
|
@ -299,6 +319,10 @@ public abstract class ContentBlock
|
|||
case ResourceLinkBlock resourceLink:
|
||||
writer.WriteString("uri", resourceLink.Uri);
|
||||
writer.WriteString("name", resourceLink.Name);
|
||||
if (resourceLink.Title is not null)
|
||||
{
|
||||
writer.WriteString("title", resourceLink.Title);
|
||||
}
|
||||
if (resourceLink.Description is not null)
|
||||
{
|
||||
writer.WriteString("description", resourceLink.Description);
|
||||
|
|
@ -311,6 +335,16 @@ public abstract class ContentBlock
|
|||
{
|
||||
writer.WriteNumber("size", resourceLink.Size.Value);
|
||||
}
|
||||
if (resourceLink.Icons is { Count: > 0 })
|
||||
{
|
||||
writer.WritePropertyName("icons");
|
||||
writer.WriteStartArray();
|
||||
foreach (var icon in resourceLink.Icons)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, icon, McpJsonUtilities.JsonContext.Default.Icon);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
break;
|
||||
|
||||
case ToolUseContentBlock toolUse:
|
||||
|
|
@ -595,6 +629,17 @@ public sealed class ResourceLinkBlock : ContentBlock
|
|||
[JsonPropertyName("name")]
|
||||
public required string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a title for this resource.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is intended for UI and end-user contexts. It is optimized to be human-readable and easily understood,
|
||||
/// even by those unfamiliar with domain-specific terminology.
|
||||
/// If not provided, <see cref="Name"/> can be used for display.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a description of what this resource represents.
|
||||
/// </summary>
|
||||
|
|
@ -638,6 +683,15 @@ public sealed class ResourceLinkBlock : ContentBlock
|
|||
/// </remarks>
|
||||
[JsonPropertyName("size")]
|
||||
public long? Size { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an optional list of icons for this resource.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can be used by clients to display the resource's icon in a user interface.
|
||||
/// </remarks>
|
||||
[JsonPropertyName("icons")]
|
||||
public IList<Icon>? Icons { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Represents a request from the assistant to call a tool.</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue