Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AnalysisMode>Recommended</AnalysisMode>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);CS1591;MAAI001</NoWarn>
<Version>1.0.19</Version>
<Version>1.0.20</Version>
<PackageVersion>$(Version)</PackageVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ namespace ManagedCode.FileContext;

/// <summary>A report block. Content follows the block JSON schema.</summary>
public sealed record FileContextReportBlock(string Type,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content = default);
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] JsonElement Content)
{
/// <summary>Creates a report block with no content.</summary>
// Bind Content through its init property so schema export can represent omitted content.
[JsonConstructor]
public FileContextReportBlock(string Type) : this(Type, default)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using Microsoft.Extensions.AI;
using UglyToad.PdfPig;

namespace ManagedCode.FileContext.Tests;
Expand All @@ -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<FileContextReportBlock>("""{"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<FileContextReportBlock[]>(
"""[{"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);

Expand Down
Loading