Skip to content

Commit 2e18372

Browse files
authored
Merge pull request #888 from Qtoss-AI/master
move data to WebStarter
2 parents a2406a6 + 1bed804 commit 2e18372

File tree

6 files changed

+34
-44
lines changed

6 files changed

+34
-44
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface IWebBrowser
2525
Task<string> ExtractData(BrowserActionParams actionParams);
2626
Task<T> EvaluateScript<T>(string contextId, string script);
2727
Task CloseBrowser(string contextId);
28+
Task<bool> IsBrowserClosed(string contextId);
2829
Task<BrowserActionResult> CloseCurrentPage(MessageInfo message);
2930
Task<BrowserActionResult> SendHttpRequest(MessageInfo message, HttpRequestParams actionParams);
3031
Task<BrowserActionResult> GetAttributeValue(MessageInfo message, ElementLocatingArgs location);

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class ConversationStateService : IConversationStateService, IDisposable
2727
private readonly ILogger _logger;
2828
private readonly IServiceProvider _services;
2929
private readonly IBotSharpRepository _db;
30-
private readonly IConversationSideCar _sidecar;
3130
private string _conversationId;
3231
/// <summary>
3332
/// States in the current round of conversation
@@ -41,12 +40,10 @@ public class ConversationStateService : IConversationStateService, IDisposable
4140
public ConversationStateService(
4241
IServiceProvider services,
4342
IBotSharpRepository db,
44-
IConversationSideCar sidecar,
4543
ILogger<ConversationStateService> logger)
4644
{
4745
_services = services;
4846
_db = db;
49-
_sidecar = sidecar;
5047
_logger = logger;
5148
_curStates = new ConversationState();
5249
_historyStates = new ConversationState();
@@ -142,8 +139,9 @@ public Dictionary<string, string> Load(string conversationId, bool isReadOnly =
142139
_conversationId = !isReadOnly ? conversationId : null;
143140
Reset();
144141

142+
var sidecar = _services.GetService<IConversationSideCar>();
145143
var endNodes = new Dictionary<string, string>();
146-
if (_sidecar?.IsEnabled() == true)
144+
if (sidecar?.IsEnabled() == true)
147145
{
148146
return endNodes;
149147
}
@@ -219,7 +217,8 @@ public Dictionary<string, string> Load(string conversationId, bool isReadOnly =
219217

220218
public void Save()
221219
{
222-
if (_conversationId == null || _sidecar?.IsEnabled() == true)
220+
var sidecar = _services.GetService<IConversationSideCar>();
221+
if (_conversationId == null || sidecar?.IsEnabled() == true)
223222
{
224223
Reset();
225224
return;

src/Plugins/BotSharp.Plugin.WebDriver/BotSharp.Plugin.WebDriver.csproj

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFramework)</TargetFramework>
@@ -16,31 +16,15 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\agent.json" />
20-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\change_checkbox.json" />
21-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\change_list_value.json" />
22-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\check_radio_button.json" />
23-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\click_button.json" />
24-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\click_element.json" />
25-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\close_browser.json" />
26-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\extract_data_from_page.json" />
27-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\go_to_page.json" />
28-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\input_user_password.json" />
29-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\input_user_text.json" />
30-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\open_browser.json" />
31-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\scroll_page.json" />
32-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\send_http_request.json" />
33-
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\take_screenshot.json" />
19+
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-web-action_on_element.fn.liquid" />
20+
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-web-go_to_page.fn.liquid" />
3421
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\instructions\instruction.liquid" />
3522
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\extract_data.liquid" />
3623
<None Remove="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\html_parser.liquid" />
3724
<None Remove="README.md" />
3825
</ItemGroup>
3926

4027
<ItemGroup>
41-
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-locate_element.json">
42-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
43-
</Content>
4428
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-action_on_element.json">
4529
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4630
</Content>
@@ -50,6 +34,9 @@
5034
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-go_to_page.json">
5135
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5236
</Content>
37+
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\functions\util-web-locate_element.json">
38+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
39+
</Content>
5340
<Content Include="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\util-web-action_on_element.fn.liquid">
5441
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5542
</Content>
@@ -59,15 +46,6 @@
5946
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\agent.json">
6047
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6148
</Content>
62-
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\instructions\instruction.liquid">
63-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
64-
</Content>
65-
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\extract_data.liquid">
66-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
67-
</Content>
68-
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\html_parser.liquid">
69-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70-
</Content>
7149
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\change_checkbox.json">
7250
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7351
</Content>
@@ -110,6 +88,15 @@
11088
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\functions\take_screenshot.json">
11189
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
11290
</Content>
91+
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\instructions\instruction.liquid">
92+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
93+
</Content>
94+
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\extract_data.liquid">
95+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
96+
</Content>
97+
<Content Include="data\agents\f3ae2a0f-e6ba-4ee1-a0b9-75d7431ff32b\templates\html_parser.liquid">
98+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
99+
</Content>
113100
</ItemGroup>
114101

115102
<ItemGroup>

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public async Task<IBrowserContext> InitContext(string ctxId, BrowserActionArgs a
5757
}
5858
else
5959
{
60-
string userDataDir = args.UserDataDir ?? $"{Path.GetTempPath()}\\playwright\\{ctxId}";
60+
string localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
61+
string userDataDir = args.UserDataDir ?? $"{localAppDataFolder}\\playwright\\{ctxId}";
6162
_contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(userDataDir, new BrowserTypeLaunchPersistentContextOptions
6263
{
6364
Headless = args.Headless,

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA
1515

1616
if (page != null)
1717
{
18-
await page.EvaluateAsync(@"() => {
19-
window.open('', '_blank');
20-
}");
18+
if (page.Url != "about:blank")
19+
{
20+
await page.EvaluateAsync(@"() => {
21+
window.open('', '_blank');
22+
}");
23+
}
2124

2225
if (args.EnableResponseCallback)
2326
{
@@ -36,13 +39,6 @@ await page.EvaluateAsync(@"() => {
3639
else
3740
{
3841
page = await _instance.NewPage(message, args);
39-
40-
Serilog.Log.Information($"goto page: {args.Url}");
41-
42-
if (args.OpenNewTab && page != null && page.Url == "about:blank")
43-
{
44-
page = await _instance.NewPage(message, args);
45-
}
4642
}
4743

4844
if (page == null)
@@ -95,6 +91,7 @@ await page.EvaluateAsync(@"() => {
9591
}
9692

9793
result.ResponseStatusCode = response.Status;
94+
result.UrlAfterAction = page.Url;
9895
if (response.Status == 200)
9996
{
10097
result.IsSuccess = true;

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ public async Task PressKey(MessageInfo message, string key)
7878
await page.Keyboard.PressAsync(key);
7979
}
8080
}
81+
82+
public async Task<bool> IsBrowserClosed(string contextId)
83+
{
84+
return !_instance.Contexts.ContainsKey(contextId);
85+
}
8186
}

0 commit comments

Comments
 (0)