Skip to content

Commit eeca631

Browse files
committed
New AI Assist pane
Actually use the max send target limits Increased initial wait time before auto connect Add UseAsPattern button in addition to copy to clipboard for ai codeblocks Refined copilot integration to use account specific urls for full model access Refactored to make AI control more independent from rest of the project Migrated to external AIAssist library
1 parent 5fb484b commit eeca631

11 files changed

Lines changed: 221 additions & 11 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "PilotAIAssistantControl"]
2+
path = PilotAIAssistantControl
3+
url = https://github.com/mitchcapper/PilotAIAssistantControl

PilotAIAssistantControl

Submodule PilotAIAssistantControl added at 1daf03c

RegExpressWPFNET/RegExpressLibrary/IRegexEngine.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,27 @@ namespace RegExpressLibrary
1414

1515
public delegate void RegexEngineOptionsChanged( IRegexEngine sender, RegexEngineOptionsChangedArgs args );
1616

17+
public interface IBaseEngine
18+
{
19+
string Name { get; }
20+
string? ExportOptions( ); // (JSON)
21+
}
22+
public interface IAIBase : IBaseEngine
23+
{
24+
string AIPatternType => "Regex";
25+
string AIPatternCodeblockType => "regex";
26+
string AIAdditionalSystemPrompt => "If the language supports named capture groups, use these by default. " +
27+
"If the user has ignoring patterned whitespace enabled in the options, use multi-lines and minimal in-regex comments for complex regexes with nice whitespace formatting to make it more readable. ";
28+
29+
string ReferenceTextHeader => "Users current target text";
30+
string GetSystemPrompt( ) => $"You are a {Name} {AIPatternType} expert assistant. The user has questions about their {AIPatternType} patterns and target text. " +
31+
$"Provide {AIPatternType} patterns inside Markdown code blocks (```{AIPatternCodeblockType} ... ```). " +
32+
"Explain how the pattern works briefly. " +
33+
AIAdditionalSystemPrompt +
34+
$"They currently have these engine options enabled:\n```json\n{ExportOptions( )}\n```";
35+
}
1736

18-
public interface IRegexEngine
37+
public interface IRegexEngine : IAIBase
1938
{
2039
event RegexEngineOptionsChanged? OptionsChanged;
2140
event EventHandler? FeatureMatrixReady;
@@ -26,8 +45,6 @@ public interface IRegexEngine
2645

2746
(string Kind, string? Version) CombinedId => (Kind, Version);
2847

29-
string Name { get; }
30-
3148
string Subtitle { get; }
3249

3350
RegexEngineCapabilityEnum Capabilities { get; }
@@ -36,8 +53,6 @@ public interface IRegexEngine
3653

3754
Control GetOptionsControl( );
3855

39-
string? ExportOptions( ); // (JSON)
40-
4156
void ImportOptions( string? json );
4257

4358
RegexMatches GetMatches( ICancellable cnc, [StringSyntax( StringSyntaxAttribute.Regex )] string pattern, string text );

RegExpressWPFNET/RegExpressLibrary/InternalConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace RegExpressLibrary
1212
public static class InternalConfig
1313
{
1414
public static bool SHOW_DEBUG_BUTTONS = false;
15+
public static bool DEBUG_LOG_AI_MESSAGES = true;
16+
17+
/// <summary>
18+
/// as the target text can be long lets not keep the old versions around two options are update the target text with the new text, or remove the old one add a note and add the new one
19+
/// </summary>
20+
public static bool DONT_UPDATE_OLD_AI_TEXT_MARK_REMOVED = true;
1521
public static string[]? limited_engine_dlls;
1622
[Flags]
1723
public enum ON_EXCEPTION_ACTION

RegExpressWPFNET/RegExpressWPFNET.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<Platform Name="Any CPU" />
44
<Platform Name="x64" />
55
</Configurations>
6+
<Folder Name="/AIAssist/">
7+
<Project Path="../PilotAIAssistantControl/PilotAIAssistantControl/PilotAIAssistantControl.shproj" Id="6cd62ff6-5bd0-41d0-a512-a6587e4846da" />
8+
<Project Path="../PilotAIAssistantControl/PilotAIAssistantControlWPF/PilotAIAssistantControlWPF.csproj" />
9+
</Folder>
610
<Folder Name="/RegexEngines/" />
711
<Folder Name="/RegexEngines/Ada/">
812
<Project Path="RegexEngines/Ada/AdaPlugin/AdaPlugin.csproj" />

RegExpressWPFNET/RegExpressWPFNET/Code/TabData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public sealed class TabData
3838
class AllTabData
3939
{
4040
public List<TabData> Tabs { get; set; } = new( );
41+
public PilotAIAssistantControl.AIUserConfig AIConfig { get; set; } = new( );
42+
public bool AITabOpen { get; set; } = false;
4143
}
4244

4345

RegExpressWPFNET/RegExpressWPFNET/MainWindow.xaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:pia="clr-namespace:PilotAIAssistantControl;assembly=PilotAIAssistantControlWPF"
7+
68
xmlns:local="clr-namespace:RegExpressWPFNET"
79
xmlns:sys="clr-namespace:System;assembly=mscorlib"
810
mc:Ignorable="d"
@@ -33,12 +35,31 @@
3335
<KeyBinding Command="{x:Static local:MainWindow.MoveTabLeftCommand}" Modifiers="Ctrl+Shift+Alt" Key="Left" />
3436
<KeyBinding Command="{x:Static local:MainWindow.MoveTabRightCommand}" Modifiers="Ctrl+Shift+Alt" Key="Right" />
3537
</Window.InputBindings>
38+
<Grid>
39+
<Grid.ColumnDefinitions>
40+
<ColumnDefinition x:Name="AiColumn" MinWidth="40" Width="Auto"/>
41+
<ColumnDefinition Width="5"/>
42+
<ColumnDefinition Width="*"/>
43+
</Grid.ColumnDefinitions>
44+
45+
<pia:UCAIExpandable x:Name="ucAi" Foreground="{x:Static SystemColors.AccentColorBrush}"
46+
TargetColumn="{Binding ElementName=AiColumn}"
47+
DefaultSize="400"
48+
MinExpandedSize="200"
49+
CollapsedSize="40"/>
50+
51+
<!-- AI Expander (just the header/toggle) -->
52+
3653

37-
<Grid Margin="0 1 0 0">
54+
<!-- Resizable Splitter (visible when expanded) -->
55+
<GridSplitter x:Name="aiSplitter" Grid.Column="1" Visibility="{Binding IsExpanded, Mode=OneWay, ElementName=aiExpander, Converter={StaticResource boolNullVisibilityCollapsedConverter}}" IsTabStop="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#E0E0E0" ResizeBehavior="PreviousAndNext" />
56+
57+
<!-- Main Content -->
58+
<Grid Margin="0 1 0 0" Grid.Column="2">
3859

3960
<TextBlock x:Name="textBlockInfo" Text="Loading..." TextAlignment="Center" VerticalAlignment="Center" Panel.ZIndex="2"/>
4061

41-
<TabControl x:Name="tabControl" Visibility="Visible" SelectionChanged="tabControlMain_SelectionChanged" Panel.ZIndex="1">
62+
<TabControl x:Name="tabControl" Visibility="Visible" SelectionChanged="tabControlMain_SelectionChanged" Panel.ZIndex="1" Margin="0,-1,0,1">
4263

4364
<TabControl.Resources>
4465

@@ -187,5 +208,5 @@
187208
</TabItem>
188209
</TabControl>
189210
</Grid>
190-
211+
</Grid>
191212
</Window>

RegExpressWPFNET/RegExpressWPFNET/MainWindow.xaml.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
using System.Windows.Shapes;
2828
using System.Windows.Threading;
2929
using System.Xml;
30+
31+
using PilotAIAssistantControl;
3032
using RegExpressLibrary;
3133
using RegExpressWPFNET.Code;
3234
using Path = System.IO.Path;
@@ -130,7 +132,7 @@ private async void Window_Loaded( object sender, RoutedEventArgs e )
130132
catch( Exception exc )
131133
{
132134
_ = exc;
133-
if (RegExpressLibrary.InternalConfig.HandleException( exc ))
135+
if( RegExpressLibrary.InternalConfig.HandleException( exc ) )
134136
throw;
135137
}
136138

@@ -177,6 +179,13 @@ private async void Window_Loaded( object sender, RoutedEventArgs e )
177179
{
178180
taskBarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
179181
}
182+
183+
// Import AI settings
184+
//all_tab_data.AIConfig = new();
185+
ucAi.ImportData( all_tab_data.AIConfig );
186+
if( all_tab_data.AITabOpen )
187+
ucAi.IsExpanded = true;
188+
180189
}
181190

182191
// --- Delay effect
@@ -210,7 +219,14 @@ private void tabControlMain_SelectionChanged( object sender, SelectionChangedEve
210219
var old_metrics = old_uc_main.GetMetrics( );
211220
new_uc_main.ApplyMetrics( old_metrics, full: false );
212221
}
222+
if( new_uc_main != null )
223+
{
224+
AiOptions.CurrentTab = new_uc_main;
225+
ucAi.Configure( AiOptions );
226+
}
227+
213228
}
229+
OurIAIUIOptions AiOptions = new( );
214230

215231

216232
private void Window_Closing( object sender, System.ComponentModel.CancelEventArgs e )
@@ -429,6 +445,10 @@ void SaveAllTabData( )
429445
all_data.Tabs.Add( tab_data );
430446
}
431447

448+
449+
all_data.AIConfig = ucAi.ExportData( );
450+
all_data.AITabOpen = ucAi.IsExpanded;
451+
432452
string json = JsonSerializer.Serialize( all_data, PluginLoader.JsonOptions );
433453
string my_file = GetMyDataFile( );
434454

@@ -466,7 +486,7 @@ void SaveAllTabData( )
466486
catch( Exception exc )
467487
{
468488
_ = exc;
469-
if (InternalConfig.HandleException( exc ))
489+
if( InternalConfig.HandleException( exc ) )
470490
throw;
471491

472492
// ignore
@@ -776,10 +796,54 @@ void GoToOptions( )
776796
}
777797

778798

799+
private void AiExpander_Expanded( object sender, RoutedEventArgs e )
800+
{
801+
// Connect the AI panel to the current tab when expanded
802+
var uc_main = GetActiveUCMain( );
803+
if( uc_main != null )
804+
{
805+
AiOptions.CurrentTab = uc_main;
806+
ucAi.Configure( AiOptions );
807+
}
808+
}
809+
810+
779811
[GeneratedRegex( @"^Regex\s*(\d+)$" )]
780812
private static partial Regex HeaderParserRegex( );
781813

782814
#endregion
783815

816+
817+
818+
public class OurIAIUIOptions : AIOptions
819+
{
820+
public override string HintForUserInput => "Ask about a regex or matching...";
821+
public override string ReferenceTextDisplayName => "Target Text";
822+
public override string FormatUserQuestion( string userQuestion ) => $"Current pattern:\n```{CurrentTab.CurrentRegexEngine?.AIPatternCodeblockType}\n{CurrentTab.ucPattern.GetTextData( "\n" ).Text}\n```\n\nMy question: {userQuestion}";
823+
public UCMain? CurrentTab;
824+
825+
public override string GetCurrentReferenceText( ) => CurrentTab?.ucText.GetTextData( "\n" ).Text;
826+
public override IEnumerable<ICodeblockAction> CodeblockActions => [ GenericCodeblockAction.ClipboardAction,
827+
new GenericCodeblockAction("📝 Use as Pattern", async ( block ) =>
828+
{
829+
830+
if( CurrentTab == null ) return false;
831+
CurrentTab.ucPattern.SetText( block.Code );
832+
return true;
833+
} )
834+
{
835+
Tooltip="Use this code block as the regex pattern",
836+
FeedbackOnAction="✓ Applied!"
837+
}
838+
];
839+
840+
public override void HandleDebugMessage( string msg )
841+
{
842+
if( InternalConfig.DEBUG_LOG_AI_MESSAGES )
843+
System.Diagnostics.Debug.WriteLine( msg );
844+
}
845+
846+
public override string GetSystemPrompt( ) => CurrentTab?.CurrentRegexEngine?.GetSystemPrompt( ) ?? null;
847+
}
784848
}
785849
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"FileVersion": 2,
3+
"Id": "c9e9a9ae-4af2-3dbb-f94e-16ee9855dc0a",
4+
"Items": [
5+
{
6+
"Id": "7868a842-835e-4377-b232-38c8e2f02b85",
7+
"Command": "--text-load-file"
8+
},
9+
{
10+
"Id": "bbfe8c09-cebc-49f1-9c4b-67369a3399f9",
11+
"Command": "",
12+
"ExclusiveMode": true,
13+
"Items": [
14+
{
15+
"Id": "793b8a32-d988-4e30-b02e-404a83db8375",
16+
"Command": "c:\\temp\\scratch\\sample_stackexchange.html"
17+
},
18+
{
19+
"Id": "326917f1-1f47-4950-9993-bd61dcb8040a",
20+
"Command": "c:\\temp\\scratch\\sample_amazon.html"
21+
},
22+
{
23+
"Id": "847fd73a-98f9-457a-8ebd-786d77a9a291",
24+
"Command": "\"c:\\temp\\scratch\\gnu_short.html\""
25+
}
26+
]
27+
},
28+
{
29+
"Id": "aae8f0a5-316b-4b65-aa1d-1714b173c1b8",
30+
"Command": "--pattern-load-file"
31+
},
32+
{
33+
"Id": "a2b778c3-b2d8-42b9-ae97-f7c4d1be91b1",
34+
"Command": "",
35+
"ExclusiveMode": true,
36+
"Items": [
37+
{
38+
"Id": "eefb71fd-52e6-43c5-8f03-8b638f06efe4",
39+
"Command": "\"c:\\temp\\scratch\\xpath.html\""
40+
},
41+
{
42+
"Id": "d6dd527d-57a6-4fcf-a46d-1eb515820030",
43+
"Command": "\"c:\\temp\\scratch\\pattern.html\""
44+
}
45+
]
46+
},
47+
{
48+
"Id": "fe062e10-b4f0-43e3-9598-cc6fc69a101d",
49+
"Command": "--only-engine-dll"
50+
},
51+
{
52+
"Id": "bcfa8157-7477-45bb-932b-925e9f590f29",
53+
"Command": "",
54+
"ExclusiveMode": true,
55+
"Items": [
56+
{
57+
"Id": "8423f79d-b886-433b-b47a-94801f926ee7",
58+
"Command": "\"DotNET9Plugin.dll\""
59+
},
60+
{
61+
"Id": "fa4d5dca-980b-403a-bd95-09221883d7fb",
62+
"Command": "\"HtmlAgilityPackPlugin.dll\""
63+
}
64+
]
65+
},
66+
{
67+
"Id": "8fbf1692-be4a-4690-8634-22e0baf7ba95",
68+
"Command": "proxy",
69+
"Items": [
70+
{
71+
"Id": "235a3262-c593-4a00-bfa4-075e468bd323",
72+
"Command": "HTTPS_PROXY=http://127.0.0.1:8484",
73+
"Type": 1
74+
},
75+
{
76+
"Id": "9d945c6d-01f2-45e4-832c-330aac99ed9d",
77+
"Command": "HTTP_PROXY=http://127.0.0.1:8484",
78+
"Type": 1
79+
},
80+
{
81+
"Id": "c735c71a-97d4-41c1-9cc8-1318087bf062",
82+
"Command": "GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8484"
83+
}
84+
]
85+
}
86+
]
87+
}

RegExpressWPFNET/RegExpressWPFNET/RegExpressWPFNET.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<OutputType>WinExe</OutputType>
55
<Nullable>enable</Nullable>
66
<UseWPF>true</UseWPF>
7+
<LangVersion>preview</LangVersion>
78
<ApplicationIcon>RegExpress.ico</ApplicationIcon>
89
<ApplicationManifest>app.manifest</ApplicationManifest>
910
</PropertyGroup>
@@ -19,6 +20,12 @@
1920
</ItemGroup>
2021

2122
<ItemGroup>
23+
<PackageReference Include="MdXaml" Version="1.27.0" />
24+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.67.1" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<ProjectReference Include="..\..\PilotAIAssistantControl\PilotAIAssistantControlWPF\PilotAIAssistantControlWPF.csproj" />
2229
<ProjectReference Include="..\RegExpressLibrary\RegExpressLibrary.csproj" />
2330
</ItemGroup>
2431

0 commit comments

Comments
 (0)