Skip to content

Commit 0740e3e

Browse files
authored
Merge pull request #19 from managedcode/codex/filecontext-1.0.20
Fix report block schema export in FileContext 1.0.20
2 parents 395e452 + c3f496d commit 0740e3e

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to ManagedCode.FileContext are documented here.
44

5+
## 1.0.20
6+
7+
- Keep report block content optional when exporting AI tool schemas and deserializing report inputs.
8+
59
## 1.0.19
610

711
- Apply file, result, page, concurrency, and timeout limits only when explicitly configured or requested. Default text and document reads return the remaining content.

‎Directory.Build.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<AnalysisMode>Recommended</AnalysisMode>
1313
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1414
<NoWarn>$(NoWarn);CS1591;MAAI001</NoWarn>
15-
<Version>1.0.19</Version>
15+
<Version>1.0.20</Version>
1616
<PackageVersion>$(Version)</PackageVersion>
1717
</PropertyGroup>
1818

‎src/ManagedCode.FileContext/Documents/Reports/FileContextReportBlock.cs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ namespace ManagedCode.FileContext;
55

66
/// <summary>A report block. Content follows the block JSON schema.</summary>
77
public sealed record FileContextReportBlock(string Type,
8-
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content = default);
8+
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content)
9+
{
10+
/// <summary>Creates a report block with no content.</summary>
11+
// Bind Content through its init property so schema export can represent omitted content.
12+
[JsonConstructor]
13+
public FileContextReportBlock(string Type) : this(Type, default)
14+
{
15+
}
16+
}

‎tests/ManagedCode.FileContext.Tests/ReportInputValidationTests.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using Microsoft.Extensions.AI;
23
using UglyToad.PdfPig;
34

45
namespace ManagedCode.FileContext.Tests;
@@ -14,9 +15,13 @@ public async Task Page_break_can_omit_content()
1415
var options = new FileContextOptions { EnableWriteTools = true };
1516
var store = new ManagedCodeStorageFileStore(storage.Storage, options);
1617
var context = new FileContextService(store, options);
17-
var pageBreak = JsonSerializer.Deserialize<FileContextReportBlock>("""{"Type":"page-break"}""", StrictJson)!;
18-
var report = new FileContextReport("Report", "pages.pdf",
19-
[pageBreak, new("text", JsonSerializer.SerializeToElement(new { text = "Second page" }))], ["pdf"]);
18+
var function = AIFunctionFactory.Create(context.Documents.CreateReportAsync);
19+
function.JsonSchema.GetRawText().ShouldContain("Content", Case.Insensitive);
20+
var blocks = JsonSerializer.Deserialize<FileContextReportBlock[]>(
21+
"""[{"Type":"page-break"},{"Type":"text","Content":{"text":"Second page"}}]""", StrictJson)!;
22+
blocks[0].Content.ValueKind.ShouldBe(JsonValueKind.Undefined);
23+
blocks[1].Content.GetProperty("text").GetString().ShouldBe("Second page");
24+
var report = new FileContextReport("Report", "pages.pdf", blocks, ["pdf"]);
2025

2126
var result = await context.Documents.CreateReportAsync(report);
2227

0 commit comments

Comments
 (0)