Skip to content

Commit 256123e

Browse files
authored
.NET connector fixes/upgrades (#267)
* Fix connector config, allow to override hostname * Fix bash script to allow nodes v18 * Upgrade SK to 1.30 * Change log level for known-unsupported events
1 parent 57aa905 commit 256123e

File tree

7 files changed

+57
-41
lines changed

7 files changed

+57
-41
lines changed

examples/dotnet/dotnet-01-echo-bot/dotnet-01-echo-bot.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
14+
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
1415
</ItemGroup>
1516

1617
<PropertyGroup>

examples/dotnet/dotnet-02-message-types-demo/dotnet-02-message-types-demo.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
<ItemGroup>
1313
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
1414
<PackageReference Include="Azure.Identity" Version="1.13.1" />
15-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
15+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
1619
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
20+
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
1721
</ItemGroup>
1822

1923
<PropertyGroup>

examples/dotnet/dotnet-03-simple-chatbot/Properties/launchSettings.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/dotnet/dotnet-03-simple-chatbot/dotnet-03-simple-chatbot.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
<ItemGroup>
1313
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
1414
<PackageReference Include="Azure.Identity" Version="1.13.1" />
15-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
15+
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
1619
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
20+
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
1721
</ItemGroup>
1822

1923
<PropertyGroup>

libraries/dotnet/WorkbenchConnector/Webservice.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
461461
case "assistant.state.updated": // TODO
462462
case "file.created": // TODO
463463
case "file.deleted": // TODO
464-
default:
465464
/*
466465
{
467466
"event": "assistant.state.created",
@@ -476,7 +475,20 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
476475
}
477476
}
478477
479-
{
478+
{
479+
"event": "assistant.state.updated",
480+
"id": "9ea3f9e2923045599f3ecfdbb07713b2",
481+
"correlation_id": "26c74d31a35b4a2aa301720af2615196",
482+
"conversation_id": "483f6253-b5e1-478a-ac9e-4d1a58499c9d",
483+
"timestamp": "2024-11-26T19:01:54.446203Z",
484+
"data": {
485+
"assistant_id": "9e58298d-dbe4-4ed3-bfdf-422d1c275de4",
486+
"state_id": "history",
487+
"conversation_id": "483f6253-b5e1-478a-ac9e-4d1a58499c9d"
488+
}
489+
}
490+
491+
{
480492
"event": "file.created",
481493
"id": "9b7ba8b35699482bbe368023796a978d",
482494
"correlation_id": "40877ed10f104090a9996fbe9dd6d716",
@@ -522,7 +534,11 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
522534
}
523535
}
524536
*/
525-
log.LogWarning("Event type '{0}' not supported", eventType.HtmlEncode());
537+
log.LogInformation("Event type '{0}' not supported [TODO]", eventType.HtmlEncode());
538+
break;
539+
540+
default:
541+
log.LogWarning("Unknown event type '{0}' not supported", eventType.HtmlEncode());
526542
log.LogTrace(json);
527543
break;
528544
}

libraries/dotnet/WorkbenchConnector/WorkbenchConnector.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public virtual void DisableInitTimer()
394394

395395
public virtual void EnablePingTimer()
396396
{
397-
this._pingTimer?.Change(TimeSpan.FromMilliseconds(PingFrequencyMS), TimeSpan.FromMilliseconds(PingFrequencyMS));
397+
this._pingTimer?.Change(TimeSpan.FromMilliseconds(PingFrequencyMsecs), TimeSpan.FromMilliseconds(PingFrequencyMsecs));
398398
}
399399

400400
public virtual void EnableInitTimer()
@@ -410,16 +410,28 @@ public virtual void Init()
410410
{
411411
this.DisableInitTimer();
412412

413+
this.Log.LogTrace("Initialization in progress...");
414+
415+
// If the connector endpoint is ready (to be passed to workbench backend)
413416
if (!string.IsNullOrWhiteSpace(this.ConnectorEndpoint))
414417
{
415-
this.Log.LogTrace("Init complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
418+
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
419+
this.EnablePingTimer();
420+
return;
421+
}
422+
423+
// If the connector host is set via configuration, rather than autodetected
424+
if (!string.IsNullOrWhiteSpace(this.WorkbenchConfig.ConnectorHost))
425+
{
426+
this.ConnectorEndpoint = $"{this.WorkbenchConfig.ConnectorHost.TrimEnd('/')}/{this.WorkbenchConfig.ConnectorApiPrefix.TrimStart('/')}";
427+
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
416428
this.EnablePingTimer();
417429
return;
418430
}
419431

432+
// Autodetect the port in use and define the connector endpoint
420433
try
421434
{
422-
this.Log.LogTrace("Init in progress...");
423435
IServerAddressesFeature? feat = this._httpServer.Features.Get<IServerAddressesFeature>();
424436
if (feat == null || feat.Addresses.Count == 0)
425437
{
@@ -434,13 +446,13 @@ public virtual void Init()
434446
? $"{uri.Scheme}://127.0.0.1:{uri.Port}/{this.WorkbenchConfig.ConnectorApiPrefix.TrimStart('/')}"
435447
: $"{uri.Scheme}://127.0.0.1:/{this.WorkbenchConfig.ConnectorApiPrefix.TrimStart('/')}";
436448

437-
this.Log.LogTrace("Init complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
449+
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
438450
this.EnablePingTimer();
439451
}
440452
#pragma warning disable CA1031
441453
catch (Exception e)
442454
{
443-
this.Log.LogError(e, "Init error");
455+
this.Log.LogError(e, "Initialization error: {Message}", e.Message);
444456
this.EnableInitTimer();
445457
}
446458
#pragma warning restore CA1031
@@ -461,7 +473,7 @@ public virtual async Task PingSemanticWorkbenchBackendAsync(CancellationToken ca
461473
name = $"{this.WorkbenchConfig.ConnectorName} [{this.WorkbenchConfig.ConnectorId}]",
462474
description = this.WorkbenchConfig.ConnectorDescription,
463475
url = this.ConnectorEndpoint,
464-
online_expires_in_seconds = 2 + (int)(PingFrequencyMS / 1000)
476+
online_expires_in_seconds = 2 + (int)(PingFrequencyMsecs / 1000)
465477
};
466478

467479
await this.SendAsync(HttpMethod.Put, path, data, null, "PingSWBackend", cancellationToken).ConfigureAwait(false);
@@ -474,7 +486,7 @@ public virtual async Task PingSemanticWorkbenchBackendAsync(CancellationToken ca
474486

475487
#region internals ===========================================================================
476488

477-
private const int PingFrequencyMS = 20000;
489+
private const int PingFrequencyMsecs = 20000;
478490

479491
public void Dispose()
480492
{

tools/run-app.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ cd workbench-app
99

1010
# Check node version, it must be major version 20 (any minor), otherwise show an error and exit
1111
NODE_VERSION=$(node -v)
12-
if [[ $NODE_VERSION != v20.* ]]; then
13-
echo "Node version is $NODE_VERSION, expected 20.x.x."
12+
if [[ ! $NODE_VERSION =~ ^v(1[8-9]|[2-9][0-9]).* ]]; then
13+
echo "Node version is $NODE_VERSION, expected 18.x.x or higher."
1414

1515
# Attempt to source nvm
1616
if [ -s "$NVM_DIR/nvm.sh" ]; then
@@ -19,18 +19,18 @@ if [[ $NODE_VERSION != v20.* ]]; then
1919
export NVM_DIR="$HOME/.nvm"
2020
. "$NVM_DIR/nvm.sh"
2121
else
22-
echo "nvm not found. Please install Node 20 manually."
22+
echo "nvm not found. Please install Node 18 or higher manually."
2323
echo "See also README.md for instructions."
2424
exit 1
2525
fi
2626

27-
echo "Installing Node 20 via nvm..."
28-
nvm install 20
29-
nvm use 20
27+
echo "Installing latest LTS Node version via nvm..."
28+
nvm install --lts
29+
nvm use --lts
3030

3131
NODE_VERSION=$(node -v)
32-
if [[ $NODE_VERSION != v20.* ]]; then
33-
echo "Failed to switch to Node 20 via nvm. You have $NODE_VERSION."
32+
if [[ ! $NODE_VERSION =~ ^v(1[8-9]|[2-9][0-9]).* ]]; then
33+
echo "Failed to switch to Node 18 or higher via nvm. You have $NODE_VERSION."
3434
exit 1
3535
fi
3636
fi

0 commit comments

Comments
 (0)