Added the exact token count where the provider reports it (#989)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
j-erlerandThorsten Sommer authored and GitHub committed 2026-09-23 20:17:02 +02:00
1 parent 82986afe62
commit be1e6532fb
34 files changed
+1360 -104

No files matched your search

@@ -19,6 +19,11 @@ namespace AIStudio.Chat;
/// which is not about the next request but about the one in flight: it is what the model is
/// reading at this moment, it is what fills the window while somebody watches, and it is gone
/// again once the answer stands.
///
/// The three are kept apart, and nothing stands in two of them. The conversation so far is what a
/// provider may already have counted exactly; the draft is what nobody has counted yet; and the
/// tool conversation is what the number will lose again once the answer is there. Each of them is
/// counted once and named on its own, so that a person can tell which part they are looking at.
/// </remarks>
public sealed record ConversationParts
{
@@ -28,35 +33,62 @@ public sealed record ConversationParts
public static readonly ConversationParts NOTHING = new();
/// <summary>
/// The texts which go into the request as they are.
/// The texts of the conversation which go into the request as they are.
/// </summary>
public IReadOnlyList<string> Texts { get; init; } = [];
/// <summary>
/// The texts which belong to this moment alone.
/// The texts of the conversation which are still being written.
/// </summary>
/// <remarks>
/// They cost exactly what the others cost; what sets them apart is that they will never be seen
/// again in this shape. The sentence somebody is typing changes with the next pause, and an
/// answer being streamed is a different text three seconds later -- so remembering what they
/// cost fills memory with answers nobody will ask for again.
///
/// What a model's tools have returned so far belongs here for the same reason, although nobody
/// is writing it: it travels with every further round of one request and with nothing after
/// that, so it is measured while it matters and forgotten when the answer is there.
/// again in this shape. An answer being streamed is a different text three seconds later -- so
/// remembering what it cost fills memory with answers nobody will ask for again.
/// </remarks>
public IReadOnlyList<string> GrowingTexts { get; init; } = [];
/// <summary>
/// The documents whose content is put into the request.
/// What the tools of the running request have returned so far, along with the calls to them.
/// </summary>
/// <remarks>
/// Growing in the same way as the answer being streamed, and measured the same way. It travels
/// with every further round of one request and with nothing after that, so it is measured while
/// it matters and forgotten when the answer is there.
/// </remarks>
public IReadOnlyList<string> ToolConversation { get; init; } = [];
/// <summary>
/// The documents of the conversation whose content is put into the request.
/// </summary>
public IReadOnlyList<FileAttachment> Documents { get; init; } = [];
/// <summary>
/// How many images travel along.
/// How many images of the conversation travel along.
/// </summary>
public int Images { get; init; }
/// <summary>
/// What stands in the composer, or an empty string when nothing does.
/// </summary>
/// <remarks>
/// Changes with the next pause, so it is measured like the texts which are still being written.
/// </remarks>
public string DraftText { get; init; } = string.Empty;
/// <summary>
/// The documents attached to the composer.
/// </summary>
public IReadOnlyList<FileAttachment> DraftDocuments { get; init; } = [];
/// <summary>
/// How many images attached to the composer travel along.
/// </summary>
/// <remarks>
/// Apart from the images of the conversation, because only those can be part of what a
/// provider has already counted.
/// </remarks>
public int DraftImages { get; init; }
/// <summary>
/// Collects what a conversation would send.
/// </summary>
@@ -84,6 +116,7 @@ public sealed record ConversationParts
{
var texts = new List<string>();
var growing = new List<string>();
var toolConversation = new List<string>();
var documents = new List<FileAttachment>();
var images = 0;
@@ -117,7 +150,7 @@ public sealed record ConversationParts
// the tool conversation. A block skipped for having nothing to say is exactly the
// block whose request is growing the fastest.
//
growing.AddRange(text.PendingToolConversation);
toolConversation.AddRange(text.PendingToolConversation);
if (string.IsNullOrWhiteSpace(text.Text))
continue;
@@ -131,18 +164,24 @@ public sealed record ConversationParts
}
}
if (!string.IsNullOrWhiteSpace(draft))
growing.Add(draft);
//
// Sorted the same way as the attachments of the conversation, into lists of their own.
//
var draftDocuments = new List<FileAttachment>();
var draftImages = 0;
if (draftAttachments is not null)
Sort(draftAttachments, documents, ref images);
Sort(draftAttachments, draftDocuments, ref draftImages);
return new()
{
Texts = texts,
GrowingTexts = growing,
ToolConversation = toolConversation,
Documents = documents,
Images = imagesAreSent ? images : 0,
DraftText = string.IsNullOrWhiteSpace(draft) ? string.Empty : draft,
DraftDocuments = draftDocuments,
DraftImages = imagesAreSent ? draftImages : 0,
};
}