11using Microsoft . Extensions . AI ;
22using System . ComponentModel ;
33using System . Diagnostics ;
4+ using System . Diagnostics . CodeAnalysis ;
45using System . Text . Json ;
56using System . Text . Json . Nodes ;
67using System . Text . Json . Serialization ;
@@ -33,13 +34,13 @@ private protected ContentBlock()
3334 }
3435
3536 /// <summary>
36- /// Gets or sets the type of content.
37+ /// When overridden in a derived class, gets the type of content.
3738 /// </summary>
3839 /// <remarks>
3940 /// This determines the structure of the content object. Valid values include "image", "audio", "text", "resource", and "resource_link".
4041 /// </remarks>
4142 [ JsonPropertyName ( "type" ) ]
42- public string Type { get ; set ; } = string . Empty ;
43+ public abstract string Type { get ; }
4344
4445 /// <summary>
4546 /// Gets or sets optional annotations for the content.
@@ -49,7 +50,7 @@ private protected ContentBlock()
4950 /// and the priority level of the content. Clients can use this information to filter or prioritize content for different roles.
5051 /// </remarks>
5152 [ JsonPropertyName ( "annotations" ) ]
52- public Annotations ? Annotations { get ; init ; }
53+ public Annotations ? Annotations { get ; set ; }
5354
5455 /// <summary>
5556 /// Provides a <see cref="JsonConverter"/> for <see cref="ContentBlock"/>.
@@ -276,8 +277,8 @@ public override void Write(Utf8JsonWriter writer, ContentBlock value, JsonSerial
276277/// <summary>Represents text provided to or from an LLM.</summary>
277278public sealed class TextContentBlock : ContentBlock
278279{
279- /// <summary>Initializes the instance of the <see cref="TextContentBlock"/> class.</summary >
280- public TextContentBlock ( ) => Type = "text" ;
280+ /// <inheritdoc/ >
281+ public override string Type => "text" ;
281282
282283 /// <summary>
283284 /// Gets or sets the text content of the message.
@@ -298,8 +299,8 @@ public sealed class TextContentBlock : ContentBlock
298299/// <summary>Represents an image provided to or from an LLM.</summary>
299300public sealed class ImageContentBlock : ContentBlock
300301{
301- /// <summary>Initializes the instance of the <see cref="ImageContentBlock"/> class.</summary >
302- public ImageContentBlock ( ) => Type = "image" ;
302+ /// <inheritdoc/ >
303+ public override string Type => "image" ;
303304
304305 /// <summary>
305306 /// Gets or sets the base64-encoded image data.
@@ -331,8 +332,8 @@ public sealed class ImageContentBlock : ContentBlock
331332/// <summary>Represents audio provided to or from an LLM.</summary>
332333public sealed class AudioContentBlock : ContentBlock
333334{
334- /// <summary>Initializes the instance of the <see cref="AudioContentBlock"/> class.</summary >
335- public AudioContentBlock ( ) => Type = "audio" ;
335+ /// <inheritdoc/ >
336+ public override string Type => "audio" ;
336337
337338 /// <summary>
338339 /// Gets or sets the base64-encoded audio data.
@@ -367,8 +368,8 @@ public sealed class AudioContentBlock : ContentBlock
367368/// </remarks>
368369public sealed class EmbeddedResourceBlock : ContentBlock
369370{
370- /// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary >
371- public EmbeddedResourceBlock ( ) => Type = "resource" ;
371+ /// <inheritdoc/ >
372+ public override string Type => "resource" ;
372373
373374 /// <summary>
374375 /// Gets or sets the resource content of the message when <see cref="Type"/> is "resource".
@@ -399,20 +400,21 @@ public sealed class EmbeddedResourceBlock : ContentBlock
399400/// </remarks>
400401public sealed class ResourceLinkBlock : ContentBlock
401402{
402- /// <summary>Initializes the instance of the <see cref="ResourceLinkBlock"/> class.</summary >
403- public ResourceLinkBlock ( ) => Type = "resource_link" ;
403+ /// <inheritdoc/ >
404+ public override string Type => "resource_link" ;
404405
405406 /// <summary>
406407 /// Gets or sets the URI of this resource.
407408 /// </summary>
408409 [ JsonPropertyName ( "uri" ) ]
409- public required string Uri { get ; init ; }
410+ [ StringSyntax ( StringSyntaxAttribute . Uri ) ]
411+ public required string Uri { get ; set ; }
410412
411413 /// <summary>
412414 /// Gets or sets a human-readable name for this resource.
413415 /// </summary>
414416 [ JsonPropertyName ( "name" ) ]
415- public required string Name { get ; init ; }
417+ public required string Name { get ; set ; }
416418
417419 /// <summary>
418420 /// Gets or sets a description of what this resource represents.
@@ -431,7 +433,7 @@ public sealed class ResourceLinkBlock : ContentBlock
431433 /// </para>
432434 /// </remarks>
433435 [ JsonPropertyName ( "description" ) ]
434- public string ? Description { get ; init ; }
436+ public string ? Description { get ; set ; }
435437
436438 /// <summary>
437439 /// Gets or sets the MIME type of this resource.
@@ -447,7 +449,7 @@ public sealed class ResourceLinkBlock : ContentBlock
447449 /// </para>
448450 /// </remarks>
449451 [ JsonPropertyName ( "mimeType" ) ]
450- public string ? MimeType { get ; init ; }
452+ public string ? MimeType { get ; set ; }
451453
452454 /// <summary>
453455 /// Gets or sets the size of the raw resource content (before base64 encoding), in bytes, if known.
@@ -456,5 +458,5 @@ public sealed class ResourceLinkBlock : ContentBlock
456458 /// This can be used by applications to display file sizes and estimate context window usage.
457459 /// </remarks>
458460 [ JsonPropertyName ( "size" ) ]
459- public long ? Size { get ; init ; }
460- }
461+ public long ? Size { get ; set ; }
462+ }
0 commit comments