|
|
|
|
@@ -9,6 +9,7 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
{
|
|
|
|
|
@@ -23,6 +24,7 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
|
|
|
|
|
public class AiChatButtonViewModel : AbstractBaseVM
|
|
|
|
|
{
|
|
|
|
|
private bool isVisible;
|
|
|
|
|
private bool canExecute;
|
|
|
|
|
private AiChatButtonState buttonState;
|
|
|
|
|
|
|
|
|
|
@@ -34,11 +36,17 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled => BeWoApp.AppSettings.ShowAI && BeWoApp.HasLoggedOnUserRight(GetUserRightType());
|
|
|
|
|
|
|
|
|
|
public bool IsVisible
|
|
|
|
|
{
|
|
|
|
|
get => isVisible;
|
|
|
|
|
set => SetProperty(ref isVisible, value, nameof(IsVisible));
|
|
|
|
|
}
|
|
|
|
|
public bool CanExecute
|
|
|
|
|
{
|
|
|
|
|
get => canExecute;
|
|
|
|
|
set => SetProperty(ref canExecute, value, nameof(CanExecute));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AiChatButtonState ButtonState
|
|
|
|
|
{
|
|
|
|
|
get => buttonState;
|
|
|
|
|
@@ -47,6 +55,10 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FirePropertyChanged(nameof(IsContextSizeTooBig));
|
|
|
|
|
FirePropertyChanged(nameof(CanSendNewMessage));
|
|
|
|
|
FirePropertyChanged(nameof(CanOpenConversation));
|
|
|
|
|
|
|
|
|
|
CommandManager.InvalidateRequerySuggested();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -59,6 +71,8 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
public DelegateCommand OpenFavoritePromptsPopupCommand { get; protected set; }
|
|
|
|
|
|
|
|
|
|
public bool IsContextSizeTooBig => ButtonState == AiChatButtonState.Warning;
|
|
|
|
|
public virtual bool CanSendNewMessage => ButtonState == AiChatButtonState.Normal;
|
|
|
|
|
public bool CanOpenConversation => ButtonState == AiChatButtonState.Normal || ButtonState == AiChatButtonState.Warning;
|
|
|
|
|
|
|
|
|
|
public AiChatButtonViewModel(AiActionType aiActionType)
|
|
|
|
|
{
|
|
|
|
|
@@ -67,11 +81,12 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
if (!IsEnabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
canExecute = true;
|
|
|
|
|
canExecute = false;
|
|
|
|
|
isVisible = false;
|
|
|
|
|
|
|
|
|
|
OpenConversationPopupCommand = new DelegateCommand(OpenConversationPopup);
|
|
|
|
|
OpenAllPromptsPopupCommand = new DelegateCommand(OpenAllPromptsPopup);
|
|
|
|
|
OpenFavoritePromptsPopupCommand = new DelegateCommand(OpenFavoritePromptsPopup);
|
|
|
|
|
OpenConversationPopupCommand = new DelegateCommand(OpenConversationPopup, () => CanOpenConversation);
|
|
|
|
|
OpenAllPromptsPopupCommand = new DelegateCommand(OpenAllPromptsPopup, () => CanSendNewMessage);
|
|
|
|
|
OpenFavoritePromptsPopupCommand = new DelegateCommand(OpenFavoritePromptsPopup, () => CanSendNewMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CheckContextSize()
|
|
|
|
|
@@ -85,6 +100,15 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
var context = GetAiVisualContext();
|
|
|
|
|
if (context != null)
|
|
|
|
|
{
|
|
|
|
|
if(context.Primary is null)
|
|
|
|
|
{
|
|
|
|
|
IsVisible = false;
|
|
|
|
|
ButtonState = AiChatButtonState.Disabled;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsVisible = true;
|
|
|
|
|
|
|
|
|
|
var context2 = context.References.ToDictionary(kv => kv.Key, kv => kv.Value.ToList());
|
|
|
|
|
|
|
|
|
|
ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CheckContextSize(ActionType, context2, null),
|
|
|
|
|
@@ -99,13 +123,18 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private protected void OpenConversationPopup()
|
|
|
|
|
private protected AiConversationChatViewModel GetConversationViewModel()
|
|
|
|
|
{
|
|
|
|
|
var context = GetAiVisualContext();
|
|
|
|
|
|
|
|
|
|
var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context.References, (long)context.Primary, true);
|
|
|
|
|
var chat_viewmodel = VMFactory.CreateAiConversationChatViewModel(ActionType, context.References, (long)context.Primary, CanSendNewMessage);
|
|
|
|
|
|
|
|
|
|
BeWoApp.MainControl.WindowService.Show(chat_viewmodel);
|
|
|
|
|
return chat_viewmodel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private protected void OpenConversationPopup()
|
|
|
|
|
{
|
|
|
|
|
BeWoApp.MainControl.WindowService.Show(GetConversationViewModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private protected void OpenAllPromptsPopup()
|
|
|
|
|
@@ -135,6 +164,23 @@ namespace BeWo.ViewModel.Controls.AI
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException($"UserRightType '{ActionType}' not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ItemAccepted(AbstractBaseVM e)
|
|
|
|
|
{
|
|
|
|
|
if(e is AiPromptbausteinPromptVM prompt)
|
|
|
|
|
{
|
|
|
|
|
var vm = GetConversationViewModel();
|
|
|
|
|
vm.SendAfterLoaded = true;
|
|
|
|
|
vm.MessageInput = prompt.Prompt;
|
|
|
|
|
BeWoApp.MainControl.WindowService.Show(vm);
|
|
|
|
|
}
|
|
|
|
|
else if(e is AiPromptbausteinRoutineVM routine)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AiMenuItemTemplate
|
|
|
|
|
|