diff --git a/CHANGELOG.md b/CHANGELOG.md index 8808ea0..a0e26ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to ManagedCode.FileContext are documented here. +## 1.0.20 + +- Keep report block content optional when exporting AI tool schemas and deserializing report inputs. + ## 1.0.19 - Apply file, result, page, concurrency, and timeout limits only when explicitly configured or requested. Default text and document reads return the remaining content. diff --git a/Directory.Build.props b/Directory.Build.props index d3f91d0..de09917 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,7 +12,7 @@ Recommended true $(NoWarn);CS1591;MAAI001 - 1.0.19 + 1.0.20 $(Version) diff --git a/src/ManagedCode.FileContext/Documents/Reports/FileContextReportBlock.cs b/src/ManagedCode.FileContext/Documents/Reports/FileContextReportBlock.cs index 3a39a84..d77f76b 100644 --- a/src/ManagedCode.FileContext/Documents/Reports/FileContextReportBlock.cs +++ b/src/ManagedCode.FileContext/Documents/Reports/FileContextReportBlock.cs @@ -5,4 +5,12 @@ namespace ManagedCode.FileContext; /// A report block. Content follows the block JSON schema. public sealed record FileContextReportBlock(string Type, - [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content = default); + [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content) +{ + /// Creates a report block with no content. + // Bind Content through its init property so schema export can represent omitted content. + [JsonConstructor] + public FileContextReportBlock(string Type) : this(Type, default) + { + } +} diff --git a/tests/ManagedCode.FileContext.Tests/ReportInputValidationTests.cs b/tests/ManagedCode.FileContext.Tests/ReportInputValidationTests.cs index 9cb24be..e2e053d 100644 --- a/tests/ManagedCode.FileContext.Tests/ReportInputValidationTests.cs +++ b/tests/ManagedCode.FileContext.Tests/ReportInputValidationTests.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using Microsoft.Extensions.AI; using UglyToad.PdfPig; namespace ManagedCode.FileContext.Tests; @@ -14,9 +15,13 @@ public async Task Page_break_can_omit_content() var options = new FileContextOptions { EnableWriteTools = true }; var store = new ManagedCodeStorageFileStore(storage.Storage, options); var context = new FileContextService(store, options); - var pageBreak = JsonSerializer.Deserialize("""{"Type":"page-break"}""", StrictJson)!; - var report = new FileContextReport("Report", "pages.pdf", - [pageBreak, new("text", JsonSerializer.SerializeToElement(new { text = "Second page" }))], ["pdf"]); + var function = AIFunctionFactory.Create(context.Documents.CreateReportAsync); + function.JsonSchema.GetRawText().ShouldContain("Content", Case.Insensitive); + var blocks = JsonSerializer.Deserialize( + """[{"Type":"page-break"},{"Type":"text","Content":{"text":"Second page"}}]""", StrictJson)!; + blocks[0].Content.ValueKind.ShouldBe(JsonValueKind.Undefined); + blocks[1].Content.GetProperty("text").GetString().ShouldBe("Second page"); + var report = new FileContextReport("Report", "pages.pdf", blocks, ["pdf"]); var result = await context.Documents.CreateReportAsync(report);