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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ versions follow [Semantic Versioning](https://semver.org/).
## [Unreleased]

- `ChatRunner.SupersedesEarlierContext` sends earlier prompts' context by its label alone: the latest prompt that carries a `PromptContext` the function accepts, and every prompt after it, send their context in full, and each earlier context goes to the model as its label with a note that it is not repeated. An application that sends the same document with each prompt no longer sends a copy of it for every earlier prompt. `SaveHistory` and the views keep every context's text; nothing changes for an application that does not set it.
- A table wider than a reply shows a button at its top right corner that opens the whole table over the window (Avalonia) or the page (Blazor), where it scrolls both ways. `ChatStrings.ExpandTable` labels the button, in every language the package ships.
- **Change:** both views take `Polhem.Markdown.Avalonia` and `Polhem.Markdown.Blazor` 0.8.0, and with them `Polhem.Markdown` 0.8.0 and the viewer fixes since 0.6.1: the Avalonia viewer no longer reads a `file` image that names a Windows network share, and an unchecked task box stands out from the background. Both viewers pin `Polhem.Markdown` to exactly 0.8.0, so an application that references it itself uses 0.8.0, and one that references a viewer package itself uses 0.8.0 or later. In the Blazor view, a reply's table cells now keep their text on one line, so a wide table scrolls sideways instead of breaking its words.

## [0.6.0] - 2026-11-30

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Polhem.Chat 各套件的重要變更,每個版本只列幾項重點。每個
## [Unreleased]

- `ChatRunner.SupersedesEarlierContext` 讓較早提問的 context 只送標籤:最近一則帶有此函式接受之 `PromptContext` 的提問,以及之後的每則提問,照常送出完整 context;更早的每份 context 只以標籤加一句「不再重送」的說明交給模型。每則提問都附上同一份文件的應用程式,不再為每則較早的提問各送一份。`SaveHistory` 與兩個 view 仍保留每份 context 的全文;沒設定的應用程式行為不變。
- 比回覆寬的表格,右上角會出現一個按鈕,把整張表格蓋在視窗(Avalonia)或頁面(Blazor)上展開,可上下左右捲動。按鈕文字是 `ChatStrings.ExpandTable`,套件附帶的每種語言都有翻譯。
- **變更:** 兩個 view 改用 `Polhem.Markdown.Avalonia` 與 `Polhem.Markdown.Blazor` 0.8.0,連帶使用 `Polhem.Markdown` 0.8.0,並帶入 0.6.1 之後的 viewer 修正:Avalonia viewer 不再讀取指向 Windows 網路共用資料夾的 `file` 圖片,未勾選的工作項目方框也與背景有足夠對比。兩個 viewer 都把 `Polhem.Markdown` 鎖定在 0.8.0,所以自行引用 `Polhem.Markdown` 的應用程式要用 0.8.0,自行引用 viewer 套件的要用 0.8.0 以上。Blazor view 裡回覆的表格儲存格改為不換行,寬表格會橫向捲動,不再把字拆開擠進畫面。

## [0.6.0] - 2026-11-30

Expand Down
1 change: 1 addition & 0 deletions src/Polhem.Chat.Avalonia/DefaultEntryTemplates.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
IsStreaming="{Binding IsStreaming}"
CjkFontFamily="{Binding $parent[local:ChatView].CjkFontFamily}"
CopyCodeLabel="{Binding $parent[local:ChatView].Strings.CopyCode}"
ExpandTableLabel="{Binding $parent[local:ChatView].Strings.ExpandTable}"
IsVisible="{Binding Text, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Classes="polhemChatStopped"
Expand Down
2 changes: 1 addition & 1 deletion src/Polhem.Chat.Avalonia/Polhem.Chat.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<!-- The lowest versions the control supports, not the newest: they become the minimum for every consumer. -->
<PackageReference Include="Avalonia" Version="12.0.0" />
<PackageReference Include="Polhem.Markdown.Avalonia" Version="0.6.1" />
<PackageReference Include="Polhem.Markdown.Avalonia" Version="0.8.0" />
</ItemGroup>

<!-- The default animation of the activity line (ChatView.ActivityIcon). -->
Expand Down
3 changes: 2 additions & 1 deletion src/Polhem.Chat.Blazor/ChatView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@

private static RenderFragment RenderError(ErrorEntry error) => @<div class="pch-error" role="alert">@error.Message</div>;

private RenderFragment RenderPrompt(UserPromptEntry prompt) =>

Check warning on line 195 in src/Polhem.Chat.Blazor/ChatView.razor

View workflow job for this annotation

GitHub Actions / sonarcloud

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

Check warning on line 195 in src/Polhem.Chat.Blazor/ChatView.razor

View workflow job for this annotation

GitHub Actions / sonarcloud

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.
@<div class="pch-prompt">
@if (prompt.Attachments.Count > 0 || prompt.Context.Count > 0)
{
Expand Down Expand Up @@ -245,7 +245,8 @@
}
@if (reply.Text.Length > 0)
{
<MarkdownViewer Markdown="@VisibleText.EscapeBidiControls(reply.Text)" Options="ReplyOptions" CopyCodeLabel="@S.CopyCode" IsStreaming="reply.IsStreaming" />
<MarkdownViewer Markdown="@VisibleText.EscapeBidiControls(reply.Text)" Options="ReplyOptions" CopyCodeLabel="@S.CopyCode"
ExpandTableLabel="@S.ExpandTable" IsStreaming="reply.IsStreaming" />
}
<div class="pch-reply-actions">
@if (reply.IsStopped)
Expand Down
4 changes: 2 additions & 2 deletions src/Polhem.Chat.Blazor/Polhem.Chat.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

<ItemGroup>
<!-- The lowest versions the component supports, not the newest: they become the minimum for every consumer.
Polhem.Markdown.Blazor 0.6.1 takes the same Polhem.Markdown as Polhem.Markdown.Avalonia 0.6.1, which the Avalonia
Polhem.Markdown.Blazor 0.8.0 takes the same Polhem.Markdown as Polhem.Markdown.Avalonia 0.8.0, which the Avalonia
control uses: Polhem.Markdown is pinned to an exact version, so the two front ends must agree on it. -->
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="10.0.1" />
<PackageReference Include="Polhem.Markdown.Blazor" Version="0.6.1" />
<PackageReference Include="Polhem.Markdown.Blazor" Version="0.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Polhem.Chat/ChatStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private ChatStrings(CultureInfo culture)
Reasoning = Load(nameof(Reasoning), culture);
Copy = Load(nameof(Copy), culture);
CopyCode = Load(nameof(CopyCode), culture);
ExpandTable = Load(nameof(ExpandTable), culture);
JumpToLatest = Load(nameof(JumpToLatest), culture);
EmptyTitle = Load(nameof(EmptyTitle), culture);
ToolRunning = Load(nameof(ToolRunning), culture);
Expand Down Expand Up @@ -103,6 +104,11 @@ private ChatStrings(CultureInfo culture)
/// <summary>Gets or sets the label of the button that copies a code block inside a reply.</summary>
public string CopyCode { get; set; }

/// <summary>
/// Gets or sets the label of the button that opens a table too wide for a reply over the window or the page.
/// </summary>
public string ExpandTable { get; set; }

/// <summary>Gets or sets the label of the button that scrolls back to the newest entry.</summary>
public string JumpToLatest { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions src/Polhem.Chat/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable
Polhem.Chat.ChatRunner.SupersedesEarlierContext.get -> System.Func<Polhem.Chat.PromptContext!, bool>?
Polhem.Chat.ChatRunner.SupersedesEarlierContext.set -> void
Polhem.Chat.ChatStrings.ExpandTable.get -> string!
Polhem.Chat.ChatStrings.ExpandTable.set -> void
3 changes: 3 additions & 0 deletions src/Polhem.Chat/Resources/ChatStrings.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<data name="CopyCode" xml:space="preserve">
<value>コピー</value>
</data>
<data name="ExpandTable" xml:space="preserve">
<value>表を拡大表示</value>
</data>
<data name="JumpToLatest" xml:space="preserve">
<value>最新へ移動</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Polhem.Chat/Resources/ChatStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<data name="CopyCode" xml:space="preserve">
<value>Copy</value>
</data>
<data name="ExpandTable" xml:space="preserve">
<value>Expand table</value>
</data>
<data name="JumpToLatest" xml:space="preserve">
<value>Jump to latest</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Polhem.Chat/Resources/ChatStrings.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<data name="CopyCode" xml:space="preserve">
<value>复制</value>
</data>
<data name="ExpandTable" xml:space="preserve">
<value>展开表格</value>
</data>
<data name="JumpToLatest" xml:space="preserve">
<value>回到最新</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Polhem.Chat/Resources/ChatStrings.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<data name="CopyCode" xml:space="preserve">
<value>複製</value>
</data>
<data name="ExpandTable" xml:space="preserve">
<value>展開表格</value>
</data>
<data name="JumpToLatest" xml:space="preserve">
<value>回到最新</value>
</data>
Expand Down
13 changes: 13 additions & 0 deletions tests/Polhem.Chat.Avalonia.UnitTests/ReplyMarkdownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ public Task CjkFontFamily_Set_ReachesViewer() => session.RunAsync(() =>
Assert.Equal(family, viewer.CjkFontFamily);
});

[Fact(DisplayName = "The reply's viewer labels its code and table buttons with the view's texts")]
public Task ButtonLabels_FollowTheViewsStrings() => session.RunAsync(() =>
{
var conversation = new ChatConversation();
conversation.Entries.Add(new AssistantReplyEntry("| a | b |\n| - | - |\n| 1 | 2 |"));
var view = new ChatView { Conversation = conversation, Strings = ChatStrings.ForCulture(CultureInfo.GetCultureInfo("zh-TW")) };
Show(view);
var viewer = Assert.Single(Descendants<MarkdownViewer>(EntryView(view, 0)));

Assert.Equal("複製", viewer.CopyCodeLabel);
Assert.Equal("展開表格", viewer.ExpandTableLabel);
});

[Fact(DisplayName = "A bidirectional override in a reply shows as an escape in text, inline code and code blocks, and Hebrew shows as it is")]
public Task BidiOverride_Reply_ShowsAsEscape() => session.RunAsync(() =>
{
Expand Down
18 changes: 18 additions & 0 deletions tests/Polhem.Chat.Blazor.UnitTests/ChatViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ public void Reply_Images_HostList_ShowsListedHostsOnly()
Assert.Contains("html theirs", view.Find(".pch-reply").TextContent, StringComparison.Ordinal);
}

[Fact(DisplayName = "A reply labels its code and table buttons with the view's texts")]
public void Reply_ButtonLabels_FollowTheViewsStrings()
{
var conversation = new ChatConversation();
conversation.AddUserPrompt("Hi");
var turn = conversation.BeginTurn();
turn.Apply(Update(new TextContent("```\ncode\n```\n\n| a | b |\n| - | - |\n| 1 | 2 |")));
turn.Complete();

var view = HostDriven(conversation);
view.Render(parameters => parameters.Add(v => v.Strings, ChatStrings.ForCulture(CultureInfo.GetCultureInfo("zh-TW"))));

Assert.Equal("複製", view.Find(".pch-reply .pmd-copy").GetAttribute("aria-label"));
var expand = view.Find(".pch-reply .pmd-table-expand");
Assert.Equal("展開表格", expand.GetAttribute("aria-label"));
Assert.Equal("展開表格", expand.GetAttribute("title"));
}

[Fact(DisplayName = "A bidirectional override in a reply shows as an escape in text, inline code and code blocks, and Hebrew shows as it is")]
public void Reply_BidiOverride_ShowsAsEscape()
{
Expand Down