Kept the inputs of assistants when you leave them (#1209)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Peer HogeterpandThorsten Sommer authored and GitHub committed 2026-11-28 11:52:17 +01:00
1 parent 1fbc1f4796
commit 7e2f83b19b
83 files changed
+1924 -347

No files matched your search

@@ -33,7 +33,7 @@
@if (this.Body is not null)
{
<CascadingValue Value="@this.CurrentMediaImportOwner">
<CascadingValue Value="@this.CurrentImportOwner">
<CascadingValue Value="@this">
<CascadingValue Value="@this.Component">
@this.Body
@@ -42,7 +42,7 @@
</CascadingValue>
<MudStack Row="true" AlignItems="AlignItems.Center" StretchItems="StretchItems.Start" Class="mb-3">
<MudButton Disabled="@(this.SubmitDisabled || this.IsProcessing || this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner))" Variant="Variant.Filled" OnClick="@(async () => await this.Start())" Style="@this.SubmitButtonStyle">
<MudButton Disabled="@(this.SubmitDisabled || this.IsProcessing || this.MediaTranscriptionService.IsBusy(this.CurrentImportOwner))" Variant="Variant.Filled" OnClick="@(async () => await this.Start())" Style="@this.SubmitButtonStyle">
@this.SubmitText
</MudButton>
@if (this.IsProcessing)
@@ -181,7 +181,7 @@
@if (this.ShowReset)
{
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@AppIcons.RESET" Disabled="@this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner)" OnClick="@(async () => await this.InnerResetForm())">
<MudButton Variant="Variant.Filled" Style="@this.GetResetColor()" StartIcon="@AppIcons.RESET" Disabled="@this.MediaTranscriptionService.IsBusy(this.CurrentImportOwner)" OnClick="@(async () => await this.InnerResetForm())">
@TB("Reset")
</MudButton>
}
@@ -8,9 +8,11 @@ using AIStudio.Dialogs.Settings;
using AIStudio.Tools.AIJobs;
using AIStudio.Tools.AssistantLaunch;
using AIStudio.Tools.AssistantSessions;
using AIStudio.Tools.Imports;
using AIStudio.Tools.Media;
using AIStudio.Tools.Services;
using AIStudio.Tools.ToolCallingSystem;
using AIStudio.Tools.Web;
using Microsoft.AspNetCore.Components;
@@ -65,7 +67,13 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
[Inject]
protected MediaTranscriptionService MediaTranscriptionService { get; init; } = null!;
/// <summary>
/// Loads web content for the web content readers of this assistant, also while the user is elsewhere.
/// </summary>
[Inject]
private WebContentImportService WebContentImportService { get; init; } = null!;
protected abstract string Title { get; }
protected abstract string Description { get; }
@@ -266,7 +274,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
protected CancellationTokenSource? CancellationTokenSource;
private bool isDisposed;
private AssistantSessionKey assistantSessionKey;
private MediaImportOwner CurrentMediaImportOwner => MediaImportOwner.ForAssistant(this.assistantSessionKey);
private ImportOwner CurrentImportOwner => ImportOwner.ForAssistant(this.assistantSessionKey);
private Guid? assistantSessionId;
/// <summary>
@@ -285,6 +293,21 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
private AssistantSessionSnapshot? pendingRenderedAssistantSessionSnapshot;
private AssistantSessionSnapshot? lastAttachedAssistantSessionSnapshot;
/// <summary>
/// What this assistant holds once its defaults are applied, before the user changed anything; null until
/// then, e.g., for a hidden assistant which sends the user to the overview instead.
/// </summary>
/// <remarks>
/// When the user leaves the assistant, it stores a draft only if its state differs from this one, see
/// SaveDraftIfChanged. A reset makes the state after the reset the new one.
/// </remarks>
private Dictionary<string, IAssistantSessionSnapshotField>? stateWithDefaults;
/// <summary>
/// Whether this assistant holds a text sent to it, which it keeps in a draft even when the user changed nothing else.
/// </summary>
private bool holdsSentText;
/// <summary>
/// Gets whether the Blazor component instance has already been disposed.
/// </summary>
@@ -296,7 +319,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
protected bool HasAssistantSession => this.assistantSessionId is not null;
/// <summary>Gets whether this assistant currently owns active media work.</summary>
protected bool IsMediaImportBusy => this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner);
protected bool IsMediaImportBusy => this.MediaTranscriptionService.IsBusy(this.CurrentImportOwner);
/// <summary>
/// Gets the assistant-specific identifier used to distinguish session slots.
@@ -312,6 +335,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
{
this.transferredRestrictions = textLaunchPayload.Restrictions;
this.ApplyTextLaunchPayload(textLaunchPayload);
this.holdsSentText = true;
}
this.MediaTranscriptionService.StateChanged += this.OnMediaImportStateChanged;
@@ -343,6 +367,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
this.SelectedToolIds = this.ToolRegistry.GetDefaultToolIds(this.Component);
await this.OnDefaultsAppliedAsync();
this.assistantSessionKey = new(this.Component, this.AssistantSessionInstanceId);
this.stateWithDefaults = this.CaptureAssistantSessionState();
await this.AttachAssistantSessionIfAvailable();
await this.ConsumeMediaOutcomeAsync();
}
@@ -412,7 +437,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
return;
}
if (this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner))
if (this.MediaTranscriptionService.IsBusy(this.CurrentImportOwner))
return;
var activeSession = this.AssistantSessionService.TryGetSnapshot(this.assistantSessionKey);
@@ -1095,11 +1120,13 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
private async Task InnerResetForm()
{
if ((this.AssistantSessionService.TryGetSnapshot(this.assistantSessionKey)?.IsActive ?? false)
|| this.MediaTranscriptionService.IsBusy(this.CurrentMediaImportOwner))
|| this.MediaTranscriptionService.IsBusy(this.CurrentImportOwner)
|| this.WebContentImportService.IsBusy(this.CurrentImportOwner))
return;
await this.AssistantSessionService.ClearAsync(this.assistantSessionKey);
this.MediaTranscriptionService.ClearOwnerState(this.CurrentMediaImportOwner);
this.MediaTranscriptionService.ClearOwnerState(this.CurrentImportOwner);
this.WebContentImportService.ClearOwnerState(this.CurrentImportOwner);
this.assistantSessionId = null;
this.ClearConversationState();
@@ -1119,6 +1146,10 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
this.InputIsValid = false;
this.InputIssues = [];
// The draft is gone with the reset, see ClearAsync above, and the form starts anew:
this.stateWithDefaults = this.CaptureAssistantSessionState();
this.holdsSentText = false;
if (this.Form is not null)
await this.Form.ResetValidationAsync();
@@ -1143,6 +1174,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
protected override void DisposeResources()
{
this.SaveDraftIfChanged();
this.MediaTranscriptionService.StateChanged -= this.OnMediaImportStateChanged;
this.isDisposed = true;
try
@@ -1159,9 +1191,9 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
}
/// <summary>Refreshes assistant actions when the shared import lane changes.</summary>
private void OnMediaImportStateChanged(MediaImportOwner owner)
private void OnMediaImportStateChanged(ImportOwner owner)
{
if (owner == this.CurrentMediaImportOwner)
if (owner == this.CurrentImportOwner)
this.InvokeAsync(async () =>
{
await this.ConsumeMediaOutcomeAsync();
@@ -1172,7 +1204,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
/// <summary>Consumes a terminal media notification when this assistant is visible.</summary>
private async Task ConsumeMediaOutcomeAsync()
{
var outcome = this.MediaTranscriptionService.TryConsumeOutcome(this.CurrentMediaImportOwner);
var outcome = this.MediaTranscriptionService.TryConsumeOutcome(this.CurrentImportOwner);
if (outcome is null)
return;
@@ -1261,6 +1293,12 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
/// <returns>A task that completes after the session was attached.</returns>
private async Task AttachAssistantSessionIfAvailable()
{
//
// A draft gives way to a run, which is newer, and to a text sent here, which the user chose to work on.
// It is taken in any case, so that a draft from before the user chose to discard inputs is gone, too:
//
var draft = this.AssistantSessionService.TryTakeDraft(this.assistantSessionKey);
var snapshot = this.AssistantSessionService.TryGetSnapshot(this.assistantSessionKey);
if (snapshot?.IsActive ?? false)
{
@@ -1269,10 +1307,73 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
}
snapshot = this.AssistantSessionService.TryTakeInactiveSnapshot(this.assistantSessionKey);
if (snapshot is null)
if (snapshot is not null)
{
await this.AttachAssistantSession(snapshot, restoreClientOnlyContent: true);
return;
}
if (draft is not null && !this.holdsSentText && this.KeepsInputsWhenLeaving)
await this.RestoreDraft(draft);
}
/// <summary>
/// Restores what this assistant held when the user left it, see SaveDraftIfChanged.
/// </summary>
/// <remarks>
/// A draft is not a run, so this component takes over no session ID and does not count as attached to a
/// session: an assistant such as the I18N one loads its data anew, as on any other start. Flags of work
/// in progress stay as they are, see AssistantSessionStateKey.IsKeptOutOfDrafts.
/// </remarks>
/// <param name="draft">The draft to restore.</param>
/// <returns>A task that completes after the component was refreshed.</returns>
private async Task RestoreDraft(AssistantSessionSnapshot draft)
{
this.ImportAssistantSessionState(draft.State, isDraft: true);
await this.OnAssistantSessionAttachedAsync(draft);
this.pendingRenderedAssistantSessionSnapshot = draft;
await this.RefreshAssistantUIAsync();
}
/// <summary>
/// Gets whether assistants keep the inputs of the user when the user leaves them, as the user or the
/// organization chose on the assistants page, see DataAssistantsPage.InputsWhenLeaving.
/// </summary>
/// <remarks>
/// When not, an assistant behaves as before v26.11.2: it stores no draft and starts anew. Runs are not
/// affected, since their sessions keep their state either way.
/// </remarks>
private bool KeepsInputsWhenLeaving => this.SettingsManager.ConfigurationData.AssistantsPage.InputsWhenLeaving is AssistantInputsWhenLeaving.KEEP_INPUTS;
/// <summary>
/// Stores what this assistant holds as a draft, so that it is there again when the user comes back.
/// </summary>
/// <remarks>
/// While a run goes on, its session keeps the state, so there is no draft. Neither is there one while
/// the assistant holds just its defaults, see IsWorthADraft, nor when the user chose to discard the
/// inputs, see KeepsInputsWhenLeaving. This runs while the component is disposed, so it must neither
/// wait nor throw.
/// </remarks>
private void SaveDraftIfChanged()
{
if (this.stateWithDefaults is null || !this.KeepsInputsWhenLeaving)
return;
await this.AttachAssistantSession(snapshot, restoreClientOnlyContent: true);
try
{
if (this.AssistantSessionService.TryGetSnapshot(this.assistantSessionKey)?.IsActive ?? false)
return;
var state = this.CaptureAssistantSessionState();
if (!IsWorthADraft(state, this.stateWithDefaults, this.holdsSentText))
return;
this.AssistantSessionService.SaveDraft(this.assistantSessionKey, this.Title, this.ChatThread, state);
}
catch (Exception e)
{
this.Logger.LogError(e, "Could not store the draft of the assistant '{AssistantTitle}'.", this.Title);
}
}
/// <summary>
@@ -1367,9 +1468,10 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
/// Restores the base assistant state and assistant-specific typed state values from a session snapshot.
/// </summary>
/// <param name="state">The captured assistant state to import.</param>
private void ImportAssistantSessionState(IReadOnlyDictionary<string, IAssistantSessionSnapshotField> state)
/// <param name="isDraft">Whether the state comes from a draft rather than from a run.</param>
private void ImportAssistantSessionState(IReadOnlyDictionary<string, IAssistantSessionSnapshotField> state, bool isDraft = false)
{
var reader = new AssistantSessionStateReader(state, this.Title);
var reader = new AssistantSessionStateReader(state, this.Title, isDraft);
reader.Restore(PROVIDER_SETTINGS_STATE_KEY, value => this.ProviderSettings = value);
reader.Restore(INPUT_IS_VALID_STATE_KEY, value => this.InputIsValid = value);
reader.Restore(CURRENT_PROFILE_STATE_KEY, value => this.CurrentProfile = value);
@@ -29,14 +29,14 @@ public abstract class AssistantLowerBase : MSGComponentBase
private protected static readonly TimeSpan STREAMING_CHECKPOINT_MIN_TIME = TimeSpan.FromSeconds(3);
protected static readonly AssistantSessionStateKey<AIStudio.Settings.Provider> PROVIDER_SETTINGS_STATE_KEY = new(nameof(ProviderSettings));
protected static readonly AssistantSessionStateKey<bool> INPUT_IS_VALID_STATE_KEY = new(nameof(InputIsValid));
protected static readonly AssistantSessionStateKey<bool> INPUT_IS_VALID_STATE_KEY = new(nameof(InputIsValid), isDerived: true);
protected static readonly AssistantSessionStateKey<Profile> CURRENT_PROFILE_STATE_KEY = new(nameof(CurrentProfile));
protected static readonly AssistantSessionStateKey<ChatTemplate> CURRENT_CHAT_TEMPLATE_STATE_KEY = new(nameof(CurrentChatTemplate));
protected static readonly AssistantSessionStateKey<ChatThread?> CHAT_THREAD_STATE_KEY = new(nameof(ChatThread));
protected static readonly AssistantSessionStateKey<IContent?> LAST_USER_PROMPT_STATE_KEY = new(nameof(LastUserPrompt));
protected static readonly AssistantSessionStateKey<ContentBlock?> RESULTING_CONTENT_BLOCK_STATE_KEY = new(nameof(ResultingContentBlock));
protected static readonly AssistantSessionStateKey<string[]> INPUT_ISSUES_STATE_KEY = new(nameof(InputIssues));
protected static readonly AssistantSessionStateKey<bool> IS_PROCESSING_STATE_KEY = new(nameof(IsProcessing));
protected static readonly AssistantSessionStateKey<string[]> INPUT_ISSUES_STATE_KEY = new(nameof(InputIssues), isDerived: true);
protected static readonly AssistantSessionStateKey<bool> IS_PROCESSING_STATE_KEY = new(nameof(IsProcessing), isKeptOutOfDrafts: true);
protected static readonly AssistantSessionStateKey<HashSet<string>> SELECTED_TOOL_IDS_STATE_KEY = new("SelectedToolIds");
protected static readonly AssistantSessionStateKey<ChatRestrictions> TRANSFERRED_RESTRICTIONS_STATE_KEY = new("TransferredRestrictions");
protected static readonly AssistantSessionStateKey<string?> CUSTOM_CHAT_SYSTEM_PROMPT_STATE_KEY = new("CustomChatSystemPromptOfRun");
@@ -65,4 +65,30 @@ public abstract class AssistantLowerBase : MSGComponentBase
this.LastUserPrompt = null;
this.ResultingContentBlock = null;
}
/// <summary>
/// Decides whether an assistant which the user leaves stores what it holds as a draft.
/// </summary>
/// <remarks>
/// A text sent to the assistant is kept in any case. Otherwise, a draft needs a change from the state
/// with the defaults: a draft of just the defaults would bring back old defaults after the user changed
/// them in the settings. Only fields which count as a change are compared, see
/// IAssistantSessionSnapshotField.CountsAsChange: whether the form is valid, for example, follows from
/// the inputs and does not count as a change on its own.
/// </remarks>
/// <param name="state">The state the assistant holds now.</param>
/// <param name="stateWithDefaults">The state the assistant held once its defaults were applied.</param>
/// <param name="holdsSentText">Whether the assistant holds a text sent to it.</param>
/// <returns><c>true</c> when the assistant stores a draft; otherwise, <c>false</c>.</returns>
internal static bool IsWorthADraft(IReadOnlyDictionary<string, IAssistantSessionSnapshotField> state, IReadOnlyDictionary<string, IAssistantSessionSnapshotField> stateWithDefaults, bool holdsSentText)
{
if (holdsSentText)
return true;
var changeableFields = state.Where(field => field.Value.CountsAsChange).ToList();
var holdsSameValues = changeableFields.Count == stateWithDefaults.Count(field => field.Value.CountsAsChange)
&& changeableFields.All(field => stateWithDefaults.TryGetValue(field.Key, out var otherField) && field.Value.HasSameValueAs(otherField));
return !holdsSameValues;
}
}
@@ -28,7 +28,7 @@ public partial class AssistantBatchProcessing
private static readonly AssistantSessionStateKey<int> MAXIMUM_DELAY_SECONDS_STATE_KEY = new(nameof(maximumDelaySeconds));
private static readonly AssistantSessionStateKey<List<BatchProcessingFileResult>> FILE_RESULTS_STATE_KEY = new(nameof(fileResults));
private static readonly AssistantSessionStateKey<HashSet<string>> USED_RESULT_FILE_NAMES_STATE_KEY = new(nameof(usedResultFileNames));
private static readonly AssistantSessionStateKey<bool> IS_PROCESSING_BATCH_STATE_KEY = new(nameof(isProcessingBatch));
private static readonly AssistantSessionStateKey<bool> IS_PROCESSING_BATCH_STATE_KEY = new(nameof(isProcessingBatch), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> HAS_REPORTED_WRITE_FAILURE_STATE_KEY = new(nameof(hasReportedWriteFailure));
private static readonly AssistantSessionStateKey<int> NUM_PROCESSED_FILES_STATE_KEY = new(nameof(numProcessedFiles));
private static readonly AssistantSessionStateKey<int> NUM_TOO_LARGE_FILES_STATE_KEY = new(nameof(numTooLargeFiles));
@@ -129,11 +129,11 @@ public partial class AssistantBuilder : AssistantBaseCore<SettingsDialogAssistan
private BuilderInstallStep? failedInstallStep;
private string installFlowIssue = string.Empty;
private static readonly AssistantSessionStateKey<BuilderStep> STEP_STATE_KEY = new(nameof(step));
private static readonly AssistantSessionStateKey<bool> IS_GENERATING_STATE_KEY = new(nameof(isGenerating));
private static readonly AssistantSessionStateKey<bool> IS_CHECKING_PLUGIN_STATE_KEY = new(nameof(isCheckingPlugin));
private static readonly AssistantSessionStateKey<bool> IS_INSTALLING_PLUGIN_STATE_KEY = new(nameof(isInstallingPlugin));
private static readonly AssistantSessionStateKey<bool> IS_AUDITING_PLUGIN_STATE_KEY = new(nameof(isAuditingPlugin));
private static readonly AssistantSessionStateKey<bool> IS_ENABLING_PLUGIN_STATE_KEY = new(nameof(isEnablingPlugin));
private static readonly AssistantSessionStateKey<bool> IS_GENERATING_STATE_KEY = new(nameof(isGenerating), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_CHECKING_PLUGIN_STATE_KEY = new(nameof(isCheckingPlugin), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_INSTALLING_PLUGIN_STATE_KEY = new(nameof(isInstallingPlugin), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_AUDITING_PLUGIN_STATE_KEY = new(nameof(isAuditingPlugin), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_ENABLING_PLUGIN_STATE_KEY = new(nameof(isEnablingPlugin), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> ASSISTANT_DESCRIPTION_STATE_KEY = new(nameof(assistantDescription));
private static readonly AssistantSessionStateKey<PluginCategory> SELECTED_CATEGORY_STATE_KEY = new(nameof(selectedCategory));
private static readonly AssistantSessionStateKey<string> CUSTOM_CATEGORY_STATE_KEY = new(nameof(customCategory));
@@ -280,6 +280,30 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
#endregion
#region Overrides of MSGComponentBase
protected override void DisposeResources()
{
//
// AutoSave writes the form into the policy only once the user paused typing. A draft restores no
// policy field, see RestoreDraftState, so a change made just before leaving would be lost without
// this. Disposing must not wait, so the settings are stored in the background:
//
try
{
if (this.selectedPolicy is { } policy && this.ApplyFormToPolicy(policy, force: false))
this.SettingsManager.StoreSettings().Observe($"{nameof(DocumentAnalysisAssistant)}: storing the policy when leaving");
}
catch (Exception e)
{
this.Logger.LogError(e, "Could not store the document analysis policy when leaving the assistant.");
}
base.DisposeResources();
}
#endregion
private async Task AutoSave(bool force = false)
{
//
@@ -416,6 +440,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
private static readonly AssistantSessionStateKey<ConfidenceLevel> POLICY_MINIMUM_PROVIDER_CONFIDENCE_STATE_KEY = new(nameof(policyMinimumProviderConfidence));
private static readonly AssistantSessionStateKey<string> POLICY_PRESELECTED_PROVIDER_ID_STATE_KEY = new(nameof(policyPreselectedProviderId));
private static readonly AssistantSessionStateKey<ProfilePreselection> POLICY_PRESELECTED_PROFILE_STATE_KEY = new(nameof(policyPreselectedProfile));
private static readonly AssistantSessionStateKey<HashSet<string>> POLICY_ALLOWED_TOOL_IDS_STATE_KEY = new(nameof(policyAllowedToolIds));
private static readonly AssistantSessionStateKey<HashSet<FileAttachment>> LOADED_DOCUMENT_PATHS_STATE_KEY = new(nameof(loadedDocumentPaths));
private static readonly AssistantSessionStateKey<string> ANALYZED_POLICY_NAME_STATE_KEY = new(nameof(analyzedPolicyName));
private static readonly AssistantSessionStateKey<List<ConfigurationSelectData<string>>> AVAILABLE_LLM_PROVIDERS_STATE_KEY = new(nameof(availableLLMProviders));
@@ -434,6 +459,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
state.Set(POLICY_MINIMUM_PROVIDER_CONFIDENCE_STATE_KEY, this.policyMinimumProviderConfidence);
state.Set(POLICY_PRESELECTED_PROVIDER_ID_STATE_KEY, this.policyPreselectedProviderId);
state.Set(POLICY_PRESELECTED_PROFILE_STATE_KEY, this.policyPreselectedProfile);
state.SetHashSet(POLICY_ALLOWED_TOOL_IDS_STATE_KEY, this.policyAllowedToolIds);
state.SetHashSet(LOADED_DOCUMENT_PATHS_STATE_KEY, this.loadedDocumentPaths);
state.Set(ANALYZED_POLICY_NAME_STATE_KEY, this.analyzedPolicyName);
state.SetList(AVAILABLE_LLM_PROVIDERS_STATE_KEY, this.availableLLMProviders);
@@ -442,6 +468,12 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
/// <inheritdoc />
protected override void RestoreCustomAssistantSessionState(AssistantSessionStateReader state)
{
if (state.IsDraft)
{
this.RestoreDraftState(state);
return;
}
state.Restore(SELECTED_POLICY_STATE_KEY, value => this.selectedPolicy = value);
state.Restore(POLICY_IS_PROTECTED_STATE_KEY, value => this.policyIsProtected = value);
state.Restore(POLICY_HIDE_POLICY_DEFINITION_STATE_KEY, value => this.policyHidePolicyDefinition = value);
@@ -457,10 +489,46 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
state.Restore(POLICY_MINIMUM_PROVIDER_CONFIDENCE_STATE_KEY, value => this.policyMinimumProviderConfidence = value);
state.Restore(POLICY_PRESELECTED_PROVIDER_ID_STATE_KEY, value => this.policyPreselectedProviderId = value);
state.Restore(POLICY_PRESELECTED_PROFILE_STATE_KEY, value => this.policyPreselectedProfile = value);
//
// The tools belong to the policy as well. On opening, the form holds those of the first policy,
// which AutoSave would otherwise write into the restored one:
//
state.Restore(POLICY_ALLOWED_TOOL_IDS_STATE_KEY, value => this.policyAllowedToolIds = [..value]);
state.RestoreHashSet(LOADED_DOCUMENT_PATHS_STATE_KEY, this.loadedDocumentPaths);
state.Restore(ANALYZED_POLICY_NAME_STATE_KEY, value => this.analyzedPolicyName = value);
state.RestoreList(AVAILABLE_LLM_PROVIDERS_STATE_KEY, this.availableLLMProviders);
}
/// <summary>
/// Restores from a draft which policy was selected and what the user entered besides the policy.
/// </summary>
/// <remarks>
/// The policies live in the settings, and AutoSave writes every change of the form into them. While the
/// user was elsewhere, a policy may have changed nonetheless, e.g., through a configuration plugin of the
/// organization, or it may be gone. A draft therefore brings back none of the policy fields, which hold
/// a copy of the policy, among them its minimum provider confidence: the form takes the policy as it is
/// now. A policy which no longer exists leaves the one selected on opening.
/// </remarks>
/// <param name="draft">The reader of the draft.</param>
private void RestoreDraftState(AssistantSessionStateReader draft)
{
DataDocumentAnalysisPolicy? policyOfDraft = null;
draft.Restore(SELECTED_POLICY_STATE_KEY, value => policyOfDraft = value);
if (policyOfDraft is not null && this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies.FirstOrDefault(policy => policy.Id == policyOfDraft.Id) is { } currentPolicy)
{
this.selectedPolicy = currentPolicy;
this.MightPreselectValues();
draft.Restore(POLICY_DEFINITION_EXPANDED_STATE_KEY, value =>
{
this.policyDefinitionExpanded = value;
this.documentSelectionExpanded = !value;
});
}
draft.RestoreHashSet(LOADED_DOCUMENT_PATHS_STATE_KEY, this.loadedDocumentPaths);
draft.Restore(ANALYZED_POLICY_NAME_STATE_KEY, value => this.analyzedPolicyName = value);
}
private bool IsNoPolicySelectedOrProtected => this.selectedPolicy is null || this.selectedPolicy.IsProtected;
@@ -140,6 +140,7 @@ else
var webState = this.assistantState.WebContent[webContent.Name];
<div class="@webContent.Class" style="@GetOptionalStyle(webContent.Style)">
<ReadWebContent @bind-Content="@webState.Content"
ImportTargetId="@webContent.Name"
@bind-URL="@webState.URL"
ProviderSettings="@this.ProviderSettings"
@bind-CleanerIsRunning="@webState.CleanerIsRunning"
@@ -154,7 +155,7 @@ else
{
var fileState = this.assistantState.FileContent[fileContent.Name];
<div class="@fileContent.Class" style="@GetOptionalStyle(fileContent.Style)">
<ReadFileContent @bind-FileContent="@fileState.Content" MediaImportTargetId="@fileContent.Name" EnableDragDrop="true" CatchAllDocuments="@this.HasSingleDropZone" ShowAttachedDocumentState="@fileContent.ShowAttachedDocumentState" />
<ReadFileContent @bind-FileContent="@fileState.Content" ImportTargetId="@fileContent.Name" EnableDragDrop="true" CatchAllDocuments="@this.HasSingleDropZone" ShowAttachedDocumentState="@fileContent.ShowAttachedDocumentState" />
</div>
}
break;
@@ -88,9 +88,9 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
private static readonly AssistantSessionStateKey<HashSet<string>?> ASSISTANT_TOOL_IDS_STATE_KEY = new(nameof(assistantToolIds));
private static readonly AssistantSessionStateKey<PluginAssistants?> ASSISTANT_PLUGIN_STATE_KEY = new(nameof(assistantPlugin));
private static readonly AssistantSessionStateKey<AssistantState> ASSISTANT_STATE_STATE_KEY = new(nameof(assistantState));
private static readonly AssistantSessionStateKey<Dictionary<string, string>> IMAGE_CACHE_STATE_KEY = new(nameof(imageCache));
private static readonly AssistantSessionStateKey<HashSet<string>> EXECUTING_BUTTON_ACTIONS_STATE_KEY = new(nameof(executingButtonActions));
private static readonly AssistantSessionStateKey<HashSet<string>> EXECUTING_SWITCH_ACTIONS_STATE_KEY = new(nameof(executingSwitchActions));
private static readonly AssistantSessionStateKey<Dictionary<string, string>> IMAGE_CACHE_STATE_KEY = new(nameof(imageCache), isDerived: true);
private static readonly AssistantSessionStateKey<HashSet<string>> EXECUTING_BUTTON_ACTIONS_STATE_KEY = new(nameof(executingButtonActions), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<HashSet<string>> EXECUTING_SWITCH_ACTIONS_STATE_KEY = new(nameof(executingSwitchActions), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> PLUGIN_PATH_STATE_KEY = new(nameof(pluginPath));
private static readonly AssistantSessionStateKey<PluginAssistantAudit?> AUDIT_STATE_KEY = new(nameof(audit));
private static readonly AssistantSessionStateKey<string> SECURITY_MESSAGE_STATE_KEY = new(nameof(securityMessage));
@@ -124,6 +124,12 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
/// <inheritdoc />
protected override void RestoreCustomAssistantSessionState(AssistantSessionStateReader state)
{
if (state.IsDraft)
{
this.RestoreDraftState(state);
return;
}
state.Restore(TITLE_STATE_KEY, value => this.title = value);
state.Restore(DESCRIPTION_STATE_KEY, value => this.description = value);
state.Restore(SYSTEM_PROMPT_STATE_KEY, value => this.systemPrompt = value);
@@ -143,6 +149,40 @@ public partial class AssistantDynamic : AssistantBaseCore<NoSettingsPanel>
state.Restore(SHARES_ASSISTANT_NAME_STATE_KEY, value => this.sharesAssistantName = value);
}
/// <summary>
/// Restores from a draft what the user entered into the form.
/// </summary>
/// <remarks>
/// Everything else follows from the plugin as it is now, see OnInitialized: while the user was elsewhere,
/// the plugin may have changed, or the organization may have withdrawn its approval. A draft therefore
/// brings back neither the plugin, its audit, its security state, nor its system prompt, so that a
/// blocked assistant stays blocked. What the user entered comes back only into the same version of a
/// plugin which may start: the components of another version may differ, and a blocked assistant shows
/// no form. Flags of work in progress inside the form, such as a running content cleaner, stay cleared.
/// </remarks>
/// <param name="draft">The reader of the draft.</param>
private void RestoreDraftState(AssistantSessionStateReader draft)
{
if (this.isSecurityBlocked || this.assistantPlugin is not { } currentPlugin)
return;
PluginAssistants? pluginOfDraft = null;
draft.Restore(ASSISTANT_PLUGIN_STATE_KEY, value => pluginOfDraft = value);
if (pluginOfDraft is null || pluginOfDraft.Id != currentPlugin.Id)
return;
if (!ReferenceEquals(pluginOfDraft, currentPlugin) && !string.Equals(pluginOfDraft.ComputeAuditHash(), currentPlugin.ComputeAuditHash(), StringComparison.Ordinal))
return;
draft.Restore(ASSISTANT_STATE_STATE_KEY, value =>
{
this.assistantState.CopyFrom(value);
this.assistantState.ClearFlagsOfWorkInProgress();
});
draft.RestoreDictionary(IMAGE_CACHE_STATE_KEY, this.imageCache);
}
#region Implementation of AssistantBase
protected override void OnInitialized()
@@ -5,4 +5,17 @@ namespace AIStudio.Assistants.Dynamic;
public sealed class FileAttachmentState
{
public HashSet<FileAttachment> DocumentPaths { get; set; } = [];
/// <summary>
/// Creates a copy which shares nothing with this state.
/// </summary>
/// <returns>The copy.</returns>
public FileAttachmentState Copy() => new() { DocumentPaths = new HashSet<FileAttachment>(this.DocumentPaths, this.DocumentPaths.Comparer) };
/// <summary>
/// Tells whether another state holds the same files as this one.
/// </summary>
/// <param name="other">The state to compare with.</param>
/// <returns><c>true</c> when both states hold the same files; otherwise, <c>false</c>.</returns>
public bool HasSameInputsAs(FileAttachmentState other) => this.DocumentPaths.SetEquals(other.DocumentPaths);
}
@@ -3,4 +3,17 @@ namespace AIStudio.Assistants.Dynamic;
public sealed class FileContentState
{
public string Content { get; set; } = string.Empty;
/// <summary>
/// Creates a copy which shares nothing with this state.
/// </summary>
/// <returns>The copy.</returns>
public FileContentState Copy() => new() { Content = this.Content };
/// <summary>
/// Tells whether another state holds the same content as this one.
/// </summary>
/// <param name="other">The state to compare with.</param>
/// <returns><c>true</c> when both states hold the same content; otherwise, <c>false</c>.</returns>
public bool HasSameInputsAs(FileContentState other) => string.Equals(this.Content, other.Content, StringComparison.Ordinal);
}
@@ -7,4 +7,30 @@ public sealed class WebContentState
public bool Preselect { get; set; }
public bool PreselectContentCleaner { get; set; }
public bool CleanerIsRunning { get; set; }
/// <summary>
/// Creates a copy which shares nothing with this state.
/// </summary>
/// <returns>The copy.</returns>
public WebContentState Copy() => new()
{
Content = this.Content,
URL = this.URL,
Preselect = this.Preselect,
PreselectContentCleaner = this.PreselectContentCleaner,
CleanerIsRunning = this.CleanerIsRunning,
};
/// <summary>
/// Tells whether another state holds the same inputs as this one.
/// </summary>
/// <remarks>
/// Whether the content cleaner runs is not an input: it is work in progress, which ends with the component that started it.
/// </remarks>
/// <param name="other">The state to compare with.</param>
/// <returns><c>true</c> when both states hold the same inputs; otherwise, <c>false</c>.</returns>
public bool HasSameInputsAs(WebContentState other) => string.Equals(this.Content, other.Content, StringComparison.Ordinal)
&& string.Equals(this.URL, other.URL, StringComparison.Ordinal)
&& this.Preselect == other.Preselect
&& this.PreselectContentCleaner == other.PreselectContentCleaner;
}
@@ -282,9 +282,27 @@ public partial class AssistantERI : AssistantBaseCore<SettingsDialogERIServer>
}
/// <inheritdoc />
/// <remarks>
/// The lists of the form are those of the selected server, see MightPreselectValues, and on opening, that
/// is the first server. The restored lists therefore become lists of their own: filled into the lists of
/// the form, they would replace the lists of the first server with those of another one, and the next
/// time the settings are stored, the first server would lose its embeddings, retrieval processes, and
/// generated files. A server which no longer exists brings back nothing, so that its inputs do not end up
/// in the server selected on opening.
/// </remarks>
protected override void RestoreCustomAssistantSessionState(AssistantSessionStateReader state)
{
state.Restore(SELECTED_ERI_SERVER_STATE_KEY, value => this.selectedERIServer = value);
var serverStillExists = true;
state.Restore(SELECTED_ERI_SERVER_STATE_KEY, value =>
{
serverStillExists = value is null || this.SettingsManager.ConfigurationData.ERI.ERIServers.Contains(value);
if (serverStillExists)
this.selectedERIServer = value;
});
if (!serverStillExists)
return;
state.Restore(AUTO_SAVE_STATE_KEY, value => this.autoSave = value);
state.Restore(SERVER_NAME_STATE_KEY, value => this.serverName = value);
state.Restore(SERVER_DESCRIPTION_STATE_KEY, value => this.serverDescription = value);
@@ -302,12 +320,12 @@ public partial class AssistantERI : AssistantBaseCore<SettingsDialogERIServer>
state.Restore(AUTH_DESCRIPTION_STATE_KEY, value => this.authDescription = value);
state.Restore(SELECTED_OPERATING_SYSTEM_STATE_KEY, value => this.selectedOperatingSystem = value);
state.Restore(ALLOWED_LLM_PROVIDERS_STATE_KEY, value => this.allowedLLMProviders = value);
state.RestoreList(EMBEDDINGS_STATE_KEY, this.embeddings);
state.RestoreList(RETRIEVAL_PROCESSES_STATE_KEY, this.retrievalProcesses);
state.Restore(EMBEDDINGS_STATE_KEY, value => this.embeddings = [..value]);
state.Restore(RETRIEVAL_PROCESSES_STATE_KEY, value => this.retrievalProcesses = [..value]);
state.Restore(ADDITIONAL_LIBRARIES_STATE_KEY, value => this.additionalLibraries = value);
state.Restore(WRITE_TO_FILESYSTEM_STATE_KEY, value => this.writeToFilesystem = value);
state.Restore(BASE_DIRECTORY_STATE_KEY, value => this.baseDirectory = value);
state.RestoreList(PREVIOUSLY_GENERATED_FILES_STATE_KEY, this.previouslyGeneratedFiles);
state.Restore(PREVIOUSLY_GENERATED_FILES_STATE_KEY, value => this.previouslyGeneratedFiles = [..value]);
}
private bool AreServerPresetsBlocked => !this.SettingsManager.ConfigurationData.ERI.PreselectOptions;
@@ -138,7 +138,7 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
private string? formalTranslationOfText;
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
private static readonly AssistantSessionStateKey<bool> IS_LOADING_STATE_KEY = new(nameof(isLoading));
private static readonly AssistantSessionStateKey<bool> IS_LOADING_STATE_KEY = new(nameof(isLoading), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> LOADING_ISSUE_STATE_KEY = new(nameof(loadingIssue));
private static readonly AssistantSessionStateKey<bool> LOCALIZATION_POSSIBLE_STATE_KEY = new(nameof(localizationPossible));
private static readonly AssistantSessionStateKey<string> SEARCH_STRING_STATE_KEY = new(nameof(searchString));
@@ -16009,6 +16009,12 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTBUILDER::T4
-- The language in which the assistants you build answer.
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTBUILDER::T42126731::INFORMAL"] = "The language in which the assistants you build answer."
-- When you switch to the chat or to another assistant and come back, an assistant can still show your inputs, your options, and its last result. AI Studio keeps them in memory only, never on disk, until you reset the assistant or quit AI Studio. A text which you send to the assistant from elsewhere replaces them. An assistant which is still working keeps working in the background either way.
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T2267376752"] = "When you switch to the chat or to another assistant and come back, an assistant can still show your inputs, your options, and its last result. AI Studio keeps them in memory only, never on disk, until you reset the assistant or quit AI Studio. A text which you send to the assistant from elsewhere replaces them. An assistant which is still working keeps working in the background either way."
-- When you switch to the chat or to another assistant and come back, an assistant can still show your inputs, your options, and its last result. AI Studio keeps them in memory only, never on disk, until you reset the assistant or quit AI Studio. A text which you send to the assistant from elsewhere replaces them. An assistant which is still working keeps working in the background either way.
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T2267376752::INFORMAL"] = "When you switch to the chat or to another assistant and come back, an assistant can still show your inputs, your options, and its last result. AI Studio keeps them in memory only, never on disk, until you reset the assistant or quit AI Studio. A text which you send to the assistant from elsewhere replaces them. An assistant which is still working keeps working in the background either way."
-- There are no categories to show or hide right now.
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T2279201345"] = "There are no categories to show or hide right now."
@@ -16045,6 +16051,12 @@ UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T403
-- Assistant Settings
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T4124037832"] = "Assistant Settings"
-- What should happen to your inputs when you leave an assistant?
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T700558677"] = "What should happen to your inputs when you leave an assistant?"
-- What should happen to your inputs when you leave an assistant?
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T700558677::INFORMAL"] = "What should happen to your inputs when you leave an assistant?"
-- Collapsing a category keeps the assistants page tidy. Choose whether AI Studio keeps offering its assistants elsewhere, e.g., in the "Send to ..." menu.
UI_TEXT_CONTENT["AISTUDIO::DIALOGS::SETTINGS::SETTINGSDIALOGASSISTANTSPAGE::T786145170"] = "Collapsing a category keeps the assistants page tidy. Choose whether AI Studio keeps offering its assistants elsewhere, e.g., in the \"Send to ...\" menu."
@@ -20200,6 +20212,9 @@ UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T1402851833
-- Welcome
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T1485461907"] = "Welcome"
-- Keep my inputs and the last result until I reset the assistant or quit AI Studio
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T1488089083"] = "Keep my inputs and the last result until I reset the assistant or quit AI Studio"
-- Assistants
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T1614176092"] = "Assistants"
@@ -20323,6 +20338,9 @@ UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T453866521"
-- Chat
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T578410699"] = "Chat"
-- Reset the assistant, so that it starts anew next time
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T715634053"] = "Reset the assistant, so that it starts anew next time"
-- When possible, use the LLM provider which was used for each chat in the first place
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CONFIGURATIONSELECTDATAFACTORY::T75376144"] = "When possible, use the LLM provider which was used for each chat in the first place"
@@ -68,7 +68,7 @@ public partial class AssistantLegalCheck : AssistantBaseCore<SettingsDialogLegal
private string inputQuestions = string.Empty;
private static readonly AssistantSessionStateKey<bool> SHOW_WEB_CONTENT_READER_STATE_KEY = new(nameof(showWebContentReader));
private static readonly AssistantSessionStateKey<bool> USE_CONTENT_CLEANER_STATE_KEY = new(nameof(useContentCleaner));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> WEB_CONTENT_URL_STATE_KEY = new(nameof(webContentURL));
private static readonly AssistantSessionStateKey<string> INPUT_LEGAL_DOCUMENT_STATE_KEY = new(nameof(inputLegalDocument));
private static readonly AssistantSessionStateKey<string> INPUT_QUESTIONS_STATE_KEY = new(nameof(inputQuestions));
@@ -487,7 +487,7 @@ public partial class AssistantModelComparison : AssistantBaseCore<SettingsDialog
private static readonly AssistantSessionStateKey<string> INPUT_CONTEXT_STATE_KEY = new(nameof(inputContext));
private static readonly AssistantSessionStateKey<string> INPUT_QUESTION_STATE_KEY = new(nameof(inputQuestion));
private static readonly AssistantSessionStateKey<bool> IS_COMPARING_STATE_KEY = new(nameof(isComparing));
private static readonly AssistantSessionStateKey<bool> IS_COMPARING_STATE_KEY = new(nameof(isComparing), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<int> RUN_COUNT_STATE_KEY = new(nameof(runCount));
private static readonly AssistantSessionStateKey<ModelComparisonBatch?> BATCH_STATE_KEY = new(nameof(batch));
private static readonly AssistantSessionStateKey<AIStudio.Settings.Provider> SECOND_PROVIDER_STATE_KEY = new(nameof(secondProvider));
@@ -253,7 +253,7 @@ public partial class AssistantPromptOptimizer : AssistantBaseCore<SettingsDialog
private static readonly AssistantSessionStateKey<HashSet<FileAttachment>> CUSTOM_PROMPT_GUIDE_FILES_STATE_KEY = new(nameof(customPromptGuideFiles));
private static readonly AssistantSessionStateKey<string> CURRENT_CUSTOM_PROMPT_GUIDE_PATH_STATE_KEY = new(nameof(currentCustomPromptGuidePath));
private static readonly AssistantSessionStateKey<string> CUSTOM_PROMPTING_GUIDELINE_CONTENT_STATE_KEY = new(nameof(customPromptingGuidelineContent));
private static readonly AssistantSessionStateKey<bool> IS_LOADING_CUSTOM_PROMPT_GUIDE_STATE_KEY = new(nameof(isLoadingCustomPromptGuide));
private static readonly AssistantSessionStateKey<bool> IS_LOADING_CUSTOM_PROMPT_GUIDE_STATE_KEY = new(nameof(isLoadingCustomPromptGuide), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> HAS_UPDATED_DEFAULT_RECOMMENDATIONS_STATE_KEY = new(nameof(hasUpdatedDefaultRecommendations));
private static readonly AssistantSessionStateKey<string> OPTIMIZED_PROMPT_STATE_KEY = new(nameof(optimizedPrompt));
private static readonly AssistantSessionStateKey<string> REC_CLARITY_DIRECTNESS_STATE_KEY = new(nameof(recClarityDirectness));
@@ -15,15 +15,15 @@
@T("Input")
</MudText>
<MudTextField T="string" Disabled="@this.isCleanerRunning" @bind-Value="@this.inputText" Validation="@this.ValidatingText" DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS" AdornmentIcon="@AppIcons.INPUT_TEXT" Adornment="Adornment.Start" Label="@T("Subject of analysis")" Variant="Variant.Outlined" Lines="6" Sizing="InputSizing.Auto" MaxLines="12" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<ReadFileContent @bind-FileContent="@this.inputText" MediaImportTargetId="swot-analysis-subject" EnableDragDrop="true" CatchAllDocuments="true"/>
<ReadFileContent @bind-FileContent="@this.inputText" ImportTargetId="swot-analysis-subject" EnableDragDrop="true" CatchAllDocuments="true"/>
<MudText Typo="Typo.h5" Class="mb-3 mt-6">
@T("Analysis Options")
</MudText>
<MudTextField T="string" Disabled="@this.isCleanerRunning" @bind-Value="@this.analysisGoal" Validation="@this.ValidatingAnalysisGoal" DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS" AdornmentIcon="@AppIcons.ANALYSIS_GOAL" Adornment="Adornment.Start" Label="@T("Analysis goal")" Variant="Variant.Outlined" Lines="4" Sizing="InputSizing.Auto" Class="mb-3"/>
<ReadFileContent @bind-FileContent="@this.analysisGoal" MediaImportTargetId="swot-analysis-goal" EnableDragDrop="true"/>
<ReadFileContent @bind-FileContent="@this.analysisGoal" ImportTargetId="swot-analysis-goal" EnableDragDrop="true"/>
<MudTextField T="string" Disabled="@this.isCleanerRunning" @bind-Text="@this.importantAspects" AdornmentIcon="@AppIcons.IMPORTANT_ASPECTS" Adornment="Adornment.Start" Label="@T("(Optional) Analysis focus")" HelperText="@TA("Specify topics the SWOT analysis should pay particular attention to.")" Variant="Variant.Outlined" Lines="4" Sizing="InputSizing.Auto" Class="mb-3"/>
<ReadFileContent @bind-FileContent="@this.importantAspects" MediaImportTargetId="swot-analysis-focus" EnableDragDrop="true"/>
<ReadFileContent @bind-FileContent="@this.importantAspects" ImportTargetId="swot-analysis-focus" EnableDragDrop="true"/>
<MudText Typo="Typo.h5" Class="mb-3 mt-6">
@T("Contextual Knowledge")
@@ -109,14 +109,14 @@ public partial class AssistantSWOTAnalysis : AssistantBaseCore<SettingsDialogSWO
private static readonly AssistantSessionStateKey<string> ANALYSIS_GOAL_STATE_KEY = new(nameof(analysisGoal));
private static readonly AssistantSessionStateKey<string> IMPORTANT_ASPECTS_STATE_KEY = new(nameof(importantAspects));
private static readonly AssistantSessionStateKey<HashSet<FileAttachment>> CONTEXT_MATERIALS_STATE_KEY = new(nameof(contextMaterials));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
private static readonly AssistantSessionStateKey<SwotAnalysisResult?> ANALYSIS_RESULT_STATE_KEY = new(nameof(analysisResult));
private static readonly AssistantSessionStateKey<Dictionary<SwotAnalysisCategory, SwotCategoryAnalysisProgress>> CATEGORY_ANALYSIS_PROGRESS_STATE_KEY = new(nameof(categoryAnalysisProgress));
private static readonly AssistantSessionStateKey<bool> IS_GATHERING_SHARED_RESEARCH_STATE_KEY = new(nameof(isGatheringSharedResearch));
private static readonly AssistantSessionStateKey<bool> IS_MODERATING_ANALYSIS_STATE_KEY = new(nameof(isModeratingAnalysis));
private static readonly AssistantSessionStateKey<bool> IS_REPAIRING_MODERATION_STATE_KEY = new(nameof(isRepairingModeration));
private static readonly AssistantSessionStateKey<bool> IS_GATHERING_SHARED_RESEARCH_STATE_KEY = new(nameof(isGatheringSharedResearch), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_MODERATING_ANALYSIS_STATE_KEY = new(nameof(isModeratingAnalysis), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<bool> IS_REPAIRING_MODERATION_STATE_KEY = new(nameof(isRepairingModeration), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> SHARED_RESEARCH_CONTEXT_STATE_KEY = new(nameof(sharedResearchContext));
/// <inheritdoc />
@@ -101,7 +101,7 @@ public partial class AssistantTextSummarizer : AssistantBaseCore<SettingsDialogT
private static readonly AssistantSessionStateKey<bool> USE_CONTENT_CLEANER_STATE_KEY = new(nameof(useContentCleaner));
private static readonly AssistantSessionStateKey<string> WEB_CONTENT_URL_STATE_KEY = new(nameof(webContentURL));
private static readonly AssistantSessionStateKey<string> INPUT_TEXT_STATE_KEY = new(nameof(inputText));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
private static readonly AssistantSessionStateKey<Complexity> SELECTED_COMPLEXITY_STATE_KEY = new(nameof(selectedComplexity));
@@ -107,7 +107,7 @@ public partial class AssistantTranslation : AssistantBaseCore<SettingsDialogTran
private static readonly AssistantSessionStateKey<bool> SHOW_WEB_CONTENT_READER_STATE_KEY = new(nameof(showWebContentReader));
private static readonly AssistantSessionStateKey<bool> USE_CONTENT_CLEANER_STATE_KEY = new(nameof(useContentCleaner));
private static readonly AssistantSessionStateKey<bool> LIVE_TRANSLATION_STATE_KEY = new(nameof(liveTranslation));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning));
private static readonly AssistantSessionStateKey<bool> IS_CLEANER_RUNNING_STATE_KEY = new(nameof(isCleanerRunning), isKeptOutOfDrafts: true);
private static readonly AssistantSessionStateKey<string> WEB_CONTENT_URL_STATE_KEY = new(nameof(webContentURL));
private static readonly AssistantSessionStateKey<string> INPUT_TEXT_STATE_KEY = new(nameof(inputText));
private static readonly AssistantSessionStateKey<string> INPUT_TEXT_LAST_TRANSLATION_STATE_KEY = new(nameof(inputTextLastTranslation));
@@ -1,6 +1,6 @@
@attribute [Route(Routes.ASSISTANT_VISUAL_BRIEFING)]
@using AIStudio.Assistants.SlideBuilder
@using AIStudio.Tools.Media
@using AIStudio.Tools.Imports
@using AIStudio.Tools.Rust
@inherits MSGComponentBase
@@ -39,7 +39,7 @@
}
@if (project.IsAvailable)
{
<MediaTranscriptionStatus Owner="@MediaImportOwner.ForVisualBriefing(project.BriefingId)" Compact="true"/>
<MediaTranscriptionStatus Owner="@ImportOwner.ForVisualBriefing(project.BriefingId)" Compact="true"/>
}
</MudStack>
</MudListItem>
@@ -3,7 +3,7 @@ using System.Text.Json;
using AIStudio.Chat;
using AIStudio.Dialogs;
using AIStudio.Provider;
using AIStudio.Tools.Media;
using AIStudio.Tools.Imports;
using AIStudio.Tools.Rust;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
@@ -142,7 +142,7 @@ public partial class VisualBriefingAssistant
return;
var id = this.selectedProject.BriefingId;
this.MediaTranscriptionService.ClearOwnerState(MediaImportOwner.ForVisualBriefing(id));
this.MediaTranscriptionService.ClearOwnerState(ImportOwner.ForVisualBriefing(id));
await this.Store.DeleteAsync(id);
await this.Store.ForgetSelectionAsync(id);
@@ -1,5 +1,6 @@
using AIStudio.Chat;
using AIStudio.Dialogs;
using AIStudio.Tools.Imports;
using AIStudio.Tools.Media;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
@@ -11,9 +12,9 @@ public partial class VisualBriefingAssistant
/// <summary>
/// Defines <c>CurrentMediaOwner</c> for the visual briefing feature.
/// </summary>
private MediaImportOwner CurrentMediaOwner => this.selectedBriefing is null
? new(MediaImportOwnerKind.VISUAL_BRIEFING, Guid.Empty.ToString("D"))
: MediaImportOwner.ForVisualBriefing(this.selectedBriefing.BriefingId);
private ImportOwner CurrentMediaOwner => this.selectedBriefing is null
? new(ImportOwnerKind.VISUAL_BRIEFING, Guid.Empty.ToString("D"))
: ImportOwner.ForVisualBriefing(this.selectedBriefing.BriefingId);
/// <summary>
/// Keeps source material and visual assets mutually exclusive after either list changed.
@@ -130,9 +131,9 @@ public partial class VisualBriefingAssistant
/// <summary>
/// Defines <c>MediaStateChanged</c> for the visual briefing feature.
/// </summary>
private void MediaStateChanged(MediaImportOwner owner)
private void MediaStateChanged(ImportOwner owner)
{
if (owner.Kind is not MediaImportOwnerKind.VISUAL_BRIEFING ||
if (owner.Kind is not ImportOwnerKind.VISUAL_BRIEFING ||
!Guid.TryParse(owner.Id, out var briefingId))
return;
@@ -167,7 +168,7 @@ public partial class VisualBriefingAssistant
private async Task ConsumePendingMediaOutcomesAsync()
{
foreach (var project in this.projects)
await this.ConsumeMediaOutcomeAsync(MediaImportOwner.ForVisualBriefing(project.BriefingId));
await this.ConsumeMediaOutcomeAsync(ImportOwner.ForVisualBriefing(project.BriefingId));
}
/// <summary>
@@ -181,7 +182,7 @@ public partial class VisualBriefingAssistant
/// different briefing is open still gets reported.
/// </remarks>
/// <param name="owner">The briefing whose media import finished.</param>
private async Task ConsumeMediaOutcomeAsync(MediaImportOwner owner)
private async Task ConsumeMediaOutcomeAsync(ImportOwner owner)
{
var outcome = this.MediaTranscriptionService.TryConsumeOutcome(owner);
if (outcome is null)
@@ -1,4 +1,5 @@
using AIStudio.Chat;
using AIStudio.Tools.Imports;
using AIStudio.Tools.Media;
namespace AIStudio.Assistants.VisualBriefing;
@@ -11,15 +12,15 @@ public sealed class VisualBriefingTranscriptStorage(VisualBriefingStore store) :
/// <summary>
/// Defines <c>CanStore</c> for the visual briefing feature.
/// </summary>
public bool CanStore(MediaImportOwner owner) =>
owner.Kind is MediaImportOwnerKind.VISUAL_BRIEFING &&
public bool CanStore(ImportOwner owner) =>
owner.Kind is ImportOwnerKind.VISUAL_BRIEFING &&
Guid.TryParse(owner.Id, out _);
/// <summary>
/// Defines <c>StoreAsync</c> for the visual briefing feature.
/// </summary>
public async Task<FileAttachment> StoreAsync(
MediaImportTarget target,
ImportTarget target,
string originalMediaPath,
string transcript,
CancellationToken token)