mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-07-07 14:26:27 +00:00
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
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
78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
using System.Text;
|
|
|
|
namespace AIStudio.Tools.AssistantSessions;
|
|
|
|
/// <summary>
|
|
/// Collects typed assistant session state values for a snapshot.
|
|
/// </summary>
|
|
public sealed class AssistantSessionStateWriter
|
|
{
|
|
/// <summary>
|
|
/// Stores captured fields by their stable dictionary names.
|
|
/// </summary>
|
|
private readonly Dictionary<string, IAssistantSessionSnapshotField> fields = new(StringComparer.Ordinal);
|
|
|
|
/// <summary>
|
|
/// Stores a typed state value.
|
|
/// </summary>
|
|
/// <typeparam name="T">The value type.</typeparam>
|
|
/// <param name="key">The typed state key.</param>
|
|
/// <param name="value">The captured value.</param>
|
|
public void Set<T>(AssistantSessionStateKey<T> key, T value)
|
|
{
|
|
this.fields[key.Name] = new AssistantSessionSnapshotField<T>(value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stores a list copy.
|
|
/// </summary>
|
|
/// <typeparam name="T">The list item type.</typeparam>
|
|
/// <param name="key">The typed state key.</param>
|
|
/// <param name="values">The values to copy.</param>
|
|
public void SetList<T>(AssistantSessionStateKey<List<T>> key, IEnumerable<T> values)
|
|
{
|
|
this.Set(key, values.ToList());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stores a hash set copy.
|
|
/// </summary>
|
|
/// <typeparam name="T">The set item type.</typeparam>
|
|
/// <param name="key">The typed state key.</param>
|
|
/// <param name="values">The values to copy.</param>
|
|
public void SetHashSet<T>(AssistantSessionStateKey<HashSet<T>> key, IEnumerable<T> values)
|
|
{
|
|
this.Set(key, values.ToHashSet());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stores a dictionary copy.
|
|
/// </summary>
|
|
/// <typeparam name="TKey">The dictionary key type.</typeparam>
|
|
/// <typeparam name="TValue">The dictionary value type.</typeparam>
|
|
/// <param name="key">The typed state key.</param>
|
|
/// <param name="values">The values to copy.</param>
|
|
public void SetDictionary<TKey, TValue>(AssistantSessionStateKey<Dictionary<TKey, TValue>> key, IDictionary<TKey, TValue> values) where TKey : notnull
|
|
{
|
|
this.Set(key, new Dictionary<TKey, TValue>(values));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stores the current text from a string builder.
|
|
/// </summary>
|
|
/// <param name="key">The typed state key.</param>
|
|
/// <param name="value">The string builder to read.</param>
|
|
public void SetStringBuilder(AssistantSessionStateKey<string> key, StringBuilder value)
|
|
{
|
|
this.Set(key, value.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the captured fields as a dictionary.
|
|
/// </summary>
|
|
/// <returns>A copied dictionary containing the captured fields.</returns>
|
|
public Dictionary<string, IAssistantSessionSnapshotField> ToDictionary()
|
|
{
|
|
return new(this.fields, StringComparer.Ordinal);
|
|
}
|
|
} |