Skip to content

Commit 26dccaf

Browse files
author
Jefferson Pires
committed
"Added API Agent feature with new classes, UI components, and options; updated version to 5.0.0; refactored and extended existing functionality for better integration."
1 parent c0722eb commit 26dccaf

9 files changed

+389
-3
lines changed

VisualChatGPTStudio2019/source.extension.vsixmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="4.0.0" Language="en-US" Publisher="Jefferson Pires" />
4+
<Identity Id="VisualChatGPTStudio2019.4854bc98-735d-4622-a0cf-30454b50aa0f" Version="5.0.0" Language="en-US" Publisher="Jefferson Pires" />
55
<DisplayName>Visual chatGPT Studio 2019</DisplayName>
66
<Description xml:space="preserve">Visual Studio extension that integrates advanced AI capabilities, enabling tasks like code suggestions, bug detection, optimization, unit test generation, and more directly within the development environment.</Description>
77
<Icon>Icon2019.png</Icon>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
3+
namespace VisualChatGPTStudioShared.Agents.ApiAgent
4+
{
5+
/// <summary>
6+
/// Represents an API definition.
7+
/// </summary>
8+
public class ApiItem
9+
{
10+
/// <summary>
11+
/// Gets or sets the API's name.
12+
/// </summary>
13+
public string Name { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the API's base URL.
17+
/// </summary>
18+
public string BaseUrl { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the collection of API tag items.
22+
/// </summary>
23+
public List<ApiTagItem> Tags { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the API's definition.
27+
/// </summary>
28+
public string Definition { get; set; }
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace VisualChatGPTStudioShared.Agents.ApiAgent
2+
{
3+
/// <summary>
4+
/// Represents a tag used in an API context.
5+
/// </summary>
6+
public class ApiTagItem
7+
{
8+
/// <summary>
9+
/// Gets or sets the tag key.
10+
/// </summary>
11+
public string Key { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets the tag value.
15+
/// </summary>
16+
public string Value { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets the type of the API tag, represented by the <see cref="ApiTagType"/> enumeration.
20+
/// </summary>
21+
public ApiTagType Type { get; set; }
22+
}
23+
24+
/// <summary>
25+
/// Represents the types of API tags, such as Header or QueryString, used for categorizing API parameters.
26+
/// </summary>
27+
public enum ApiTagType
28+
{
29+
Header,
30+
QueryString
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using JeffPires.VisualChatGPTStudio.Options.ApiAgent;
2+
using Microsoft.VisualStudio.Shell;
3+
using System.Runtime.InteropServices;
4+
using System.Windows;
5+
6+
namespace VisualChatGPTStudioShared.Options.ApiAgent
7+
{
8+
[ComVisible(true)]
9+
public class OptionApiAgent : UIElementDialogPage
10+
{
11+
protected override UIElement Child
12+
{
13+
get
14+
{
15+
return new OptionApiAgentWindow();
16+
}
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<UserControl x:Class="JeffPires.VisualChatGPTStudio.Options.ApiAgent.OptionApiAgentWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
7+
mc:Ignorable="d"
8+
Name="MyToolWindow">
9+
<ScrollViewer VerticalScrollBarVisibility="Auto">
10+
<Grid Margin="10">
11+
<Grid.RowDefinitions>
12+
<RowDefinition Height="25"/>
13+
<!-- Identification -->
14+
<RowDefinition Height="10"/>
15+
<RowDefinition Height="25"/>
16+
<!-- Base URL -->
17+
<RowDefinition Height="10"/>
18+
<RowDefinition Height="25"/>
19+
<RowDefinition Height="10"/>
20+
<RowDefinition Height="100"/>
21+
<!-- TAGs -->
22+
<RowDefinition Height="10"/>
23+
<RowDefinition Height="100"/>
24+
<!-- Definition -->
25+
<RowDefinition Height="10"/>
26+
<RowDefinition Height="25"/>
27+
<RowDefinition Height="10"/>
28+
<RowDefinition Height="Auto"/>
29+
<RowDefinition Height="10"/>
30+
<RowDefinition Height="*" MinHeight="100"/>
31+
<!-- APIs List -->
32+
</Grid.RowDefinitions>
33+
<Grid.ColumnDefinitions>
34+
<ColumnDefinition Width="Auto"/>
35+
<!-- Labels -->
36+
<ColumnDefinition Width="5"/>
37+
<ColumnDefinition Width="*"/>
38+
<!-- Inputs -->
39+
<ColumnDefinition Width="5"/>
40+
<ColumnDefinition Width="20"/>
41+
<!-- Info Icons -->
42+
</Grid.ColumnDefinitions>
43+
44+
<!-- Identification -->
45+
<Label Content="Identification:" Grid.Row="0" Grid.Column="0" />
46+
<TextBox x:Name="txtIdentification" Grid.Row="0" Grid.Column="2" FontSize="16"/>
47+
<Image Grid.Row="0" Grid.Column="4" Height="20" VerticalAlignment="Center" ToolTip="Enter a unique name to identify the API." Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/information.png" />
48+
49+
<!-- Base URL -->
50+
<Label Content="Base URL:" Grid.Row="2" Grid.Column="0" />
51+
<TextBox x:Name="txtBaseUrl" Grid.Row="2" Grid.Column="2" FontSize="16"/>
52+
<Image Grid.Row="2" Grid.Column="4" VerticalAlignment="Center" ToolTip="Enter the base URL of the API." Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/information.png" />
53+
54+
<!-- TAGs -->
55+
<Button x:Name="btnInsertTag" Content="Insert a Key/Value" Click="btnInsertTag_Click" Grid.Row="4" Grid.Column="2" HorizontalAlignment="Right" Width="150" />
56+
<Label Content="Key/Values:" Grid.Row="6" Grid.Column="0" VerticalAlignment="Top" />
57+
<DataGrid
58+
x:Name="grdTags"
59+
AutoGenerateColumns="False"
60+
Grid.Row="6"
61+
Grid.Column="2"
62+
SelectionMode="Single"
63+
SelectionUnit="FullRow"
64+
CanUserAddRows="False"
65+
CanUserReorderColumns="False"
66+
CanUserResizeColumns="True"
67+
CanUserResizeRows="True"
68+
CanUserSortColumns="False">
69+
<DataGrid.Columns>
70+
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="False" Width="1*" FontSize="14"/>
71+
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="False" Width="2*" FontSize="14"/>
72+
<DataGridTemplateColumn Header="Type" MinWidth="100">
73+
<DataGridTemplateColumn.CellTemplate>
74+
<DataTemplate>
75+
<ComboBox SelectedIndex="0">
76+
<ComboBoxItem Content="Header" />
77+
<ComboBoxItem Content="QueryString" />
78+
</ComboBox>
79+
</DataTemplate>
80+
</DataGridTemplateColumn.CellTemplate>
81+
</DataGridTemplateColumn>
82+
<DataGridTemplateColumn Header="">
83+
<DataGridTemplateColumn.CellTemplate>
84+
<DataTemplate>
85+
<Image
86+
Height="16"
87+
Width="16"
88+
HorizontalAlignment="Center"
89+
VerticalAlignment="Center"
90+
Name="btnDelete"
91+
MouseDown="btnGrdTagsDelete_Click"
92+
ToolTip="Delete this key-value pair."
93+
Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/garbage_color.png">
94+
<Image.Style>
95+
<Style TargetType="{x:Type Image}">
96+
<Setter Property="Cursor" Value="Arrow"/>
97+
<Style.Triggers>
98+
<Trigger Property="IsMouseOver" Value="True">
99+
<Setter Property="Cursor" Value="Hand"/>
100+
</Trigger>
101+
</Style.Triggers>
102+
</Style>
103+
</Image.Style>
104+
</Image>
105+
</DataTemplate>
106+
</DataGridTemplateColumn.CellTemplate>
107+
</DataGridTemplateColumn>
108+
</DataGrid.Columns>
109+
</DataGrid>
110+
<Image Grid.Row="6" Grid.Column="4" VerticalAlignment="Top" ToolTip="Define key-value pairs to be included in API requests, or to replace the key/values defined by the AI. Ideal for inserting authentication/authorization key/values." Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/information.png" />
111+
112+
<!-- Definition -->
113+
<Label Content="Definition:" Grid.Row="8" Grid.Column="0" VerticalAlignment="Top" />
114+
<TextBox x:Name="txtDefinition" Grid.Row="8" Grid.Column="2" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" />
115+
<Image Grid.Row="8" Grid.Column="4" VerticalAlignment="Top" ToolTip="Paste the API's definition (e.g., OpenAPI, Swagger) here. This allows the AI to understand the API's structure and capabilities for making requests." Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/information.png" />
116+
117+
<Button x:Name="btnInsertApi" Content="Confirm" Grid.Row="10" Grid.Column="2" HorizontalAlignment="Right" Width="150" Click="btnInsertApi_Click" />
118+
119+
<Border Grid.Row="12" Grid.Column="0" Grid.ColumnSpan="3" Height="1" Background="Gray"/>
120+
121+
<!-- APIs List -->
122+
<Label Content="APIs:" Grid.Row="14" Grid.Column="0" VerticalAlignment="Top" />
123+
<ListView x:Name="lstApis" Grid.Row="14" Grid.Column="2" >
124+
<ListView.View>
125+
<GridView>
126+
<GridViewColumn Header="API" DisplayMemberBinding="{Binding Name}" Width="Auto">
127+
<GridViewColumn.HeaderContainerStyle>
128+
<Style TargetType="GridViewColumnHeader">
129+
<Setter Property="HorizontalContentAlignment" Value="Left" />
130+
</Style>
131+
</GridViewColumn.HeaderContainerStyle>
132+
</GridViewColumn>
133+
<GridViewColumn Header="">
134+
<GridViewColumn.CellTemplate>
135+
<DataTemplate>
136+
<StackPanel Orientation="Horizontal">
137+
<Image Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/edit_color.png"
138+
Width="16" Height="16" Margin="0,0,5,0"
139+
ToolTip="Edit this API."
140+
MouseDown="btnEditApi_Click" />
141+
<Image Source="pack://application:,,,/VisualChatGPTStudio;component/Resources/garbage_color.png"
142+
Width="16" Height="16"
143+
ToolTip="Delete this API."
144+
MouseDown="btnDeleteApi_Click" />
145+
</StackPanel>
146+
</DataTemplate>
147+
</GridViewColumn.CellTemplate>
148+
</GridViewColumn>
149+
</GridView>
150+
</ListView.View>
151+
</ListView>
152+
</Grid>
153+
</ScrollViewer>
154+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System.Collections.ObjectModel;
2+
using System.Linq;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Input;
6+
using VisualChatGPTStudioShared.Agents.ApiAgent;
7+
using UserControl = System.Windows.Controls.UserControl;
8+
9+
namespace JeffPires.VisualChatGPTStudio.Options.ApiAgent
10+
{
11+
/// <summary>
12+
/// Represents a user control for displaying and interacting with option commands.
13+
/// </summary>
14+
public partial class OptionApiAgentWindow : UserControl
15+
{
16+
#region Properties
17+
18+
public ObservableCollection<ApiTagItem> Tags { get; set; } = [];
19+
public ObservableCollection<ApiItem> Apis { get; set; } = [];
20+
21+
#endregion Properties
22+
23+
#region Constructors
24+
25+
public OptionApiAgentWindow()
26+
{
27+
InitializeComponent();
28+
29+
grdTags.ItemsSource = Tags;
30+
lstApis.ItemsSource = Apis;
31+
}
32+
33+
#endregion Constructors
34+
35+
#region Event Handlers
36+
37+
private void btnInsertTag_Click(object sender, RoutedEventArgs e)
38+
{
39+
Tags.Add(new ApiTagItem { Key = string.Empty, Value = string.Empty, Type = ApiTagType.Header });
40+
}
41+
42+
private void btnGrdTagsDelete_Click(object sender, MouseButtonEventArgs e)
43+
{
44+
if (sender is Image deleteButton)
45+
{
46+
if (deleteButton.DataContext is ApiTagItem tagToDelete)
47+
{
48+
MessageBoxResult result = MessageBox.Show($"Are you sure you want to delete the tag with key '{tagToDelete.Key}'?", Utils.Constants.EXTENSION_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question);
49+
50+
if (result == MessageBoxResult.Yes)
51+
{
52+
Tags.Remove(tagToDelete);
53+
}
54+
}
55+
}
56+
}
57+
58+
private void btnInsertApi_Click(object sender, RoutedEventArgs e)
59+
{
60+
if (string.IsNullOrWhiteSpace(txtIdentification.Text) || string.IsNullOrWhiteSpace(txtBaseUrl.Text))
61+
{
62+
MessageBox.Show("Please fill in both Identification and Base URL fields before adding an API.", Utils.Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
63+
64+
return;
65+
}
66+
67+
if (string.IsNullOrWhiteSpace(txtDefinition.Text))
68+
{
69+
MessageBox.Show("Please paste the API's definition.", Utils.Constants.EXTENSION_NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
70+
71+
return;
72+
}
73+
74+
Apis.Add(new ApiItem
75+
{
76+
Name = txtIdentification.Text,
77+
BaseUrl = txtBaseUrl.Text,
78+
Tags = Tags.ToList(),
79+
Definition = txtDefinition.Text
80+
});
81+
82+
txtIdentification.Clear();
83+
txtBaseUrl.Clear();
84+
txtDefinition.Clear();
85+
Tags.Clear();
86+
}
87+
88+
private void btnEditApi_Click(object sender, MouseButtonEventArgs e)
89+
{
90+
if (lstApis.SelectedItem is ApiItem selectedApi)
91+
{
92+
txtIdentification.Text = selectedApi.Name;
93+
txtBaseUrl.Text = selectedApi.BaseUrl;
94+
txtDefinition.Text = selectedApi.Definition;
95+
Tags.Clear();
96+
97+
foreach (ApiTagItem tag in selectedApi.Tags)
98+
{
99+
Tags.Add(tag);
100+
}
101+
102+
Apis.Remove(selectedApi);
103+
}
104+
}
105+
106+
private void btnDeleteApi_Click(object sender, MouseButtonEventArgs e)
107+
{
108+
if (lstApis.SelectedItem is ApiItem selectedApi)
109+
{
110+
MessageBoxResult result = MessageBox.Show($"Are you sure you want to delete the API '{selectedApi.Name}'?", Utils.Constants.EXTENSION_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question);
111+
112+
if (result == MessageBoxResult.Yes)
113+
{
114+
Apis.Remove(selectedApi);
115+
}
116+
}
117+
}
118+
119+
#endregion Event Handlers
120+
}
121+
}

0 commit comments

Comments
 (0)