Skip to content

Commit

Permalink
.NET connector fixes/upgrades (#267)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dluc authored Nov 26, 2024
1 parent 57aa905 commit 256123e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
<ItemGroup>
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
</ItemGroup>

<PropertyGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
<ItemGroup>
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticWorkbench.Connector" Version="0.4.241125.1" />
<!-- <ProjectReference Include="..\..\..\libraries\dotnet\WorkbenchConnector\WorkbenchConnector.csproj" /> -->
</ItemGroup>

<PropertyGroup>
Expand Down
22 changes: 19 additions & 3 deletions libraries/dotnet/WorkbenchConnector/Webservice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
case "assistant.state.updated": // TODO
case "file.created": // TODO
case "file.deleted": // TODO
default:
/*
{
"event": "assistant.state.created",
Expand All @@ -476,7 +475,20 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
}
}
{
{
"event": "assistant.state.updated",
"id": "9ea3f9e2923045599f3ecfdbb07713b2",
"correlation_id": "26c74d31a35b4a2aa301720af2615196",
"conversation_id": "483f6253-b5e1-478a-ac9e-4d1a58499c9d",
"timestamp": "2024-11-26T19:01:54.446203Z",
"data": {
"assistant_id": "9e58298d-dbe4-4ed3-bfdf-422d1c275de4",
"state_id": "history",
"conversation_id": "483f6253-b5e1-478a-ac9e-4d1a58499c9d"
}
}
{
"event": "file.created",
"id": "9b7ba8b35699482bbe368023796a978d",
"correlation_id": "40877ed10f104090a9996fbe9dd6d716",
Expand Down Expand Up @@ -522,7 +534,11 @@ private static IEndpointRouteBuilder UseCreateConversationEventEndpoint<TAgentCo
}
}
*/
log.LogWarning("Event type '{0}' not supported", eventType.HtmlEncode());
log.LogInformation("Event type '{0}' not supported [TODO]", eventType.HtmlEncode());
break;

default:
log.LogWarning("Unknown event type '{0}' not supported", eventType.HtmlEncode());
log.LogTrace(json);
break;
}
Expand Down
26 changes: 19 additions & 7 deletions libraries/dotnet/WorkbenchConnector/WorkbenchConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public virtual void DisableInitTimer()

public virtual void EnablePingTimer()
{
this._pingTimer?.Change(TimeSpan.FromMilliseconds(PingFrequencyMS), TimeSpan.FromMilliseconds(PingFrequencyMS));
this._pingTimer?.Change(TimeSpan.FromMilliseconds(PingFrequencyMsecs), TimeSpan.FromMilliseconds(PingFrequencyMsecs));
}

public virtual void EnableInitTimer()
Expand All @@ -410,16 +410,28 @@ public virtual void Init()
{
this.DisableInitTimer();

this.Log.LogTrace("Initialization in progress...");

// If the connector endpoint is ready (to be passed to workbench backend)
if (!string.IsNullOrWhiteSpace(this.ConnectorEndpoint))
{
this.Log.LogTrace("Init complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
this.EnablePingTimer();
return;
}

// If the connector host is set via configuration, rather than autodetected
if (!string.IsNullOrWhiteSpace(this.WorkbenchConfig.ConnectorHost))
{
this.ConnectorEndpoint = $"{this.WorkbenchConfig.ConnectorHost.TrimEnd('/')}/{this.WorkbenchConfig.ConnectorApiPrefix.TrimStart('/')}";
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
this.EnablePingTimer();
return;
}

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

this.Log.LogTrace("Init complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
this.Log.LogTrace("Initialization complete, connector endpoint: {Endpoint}", this.ConnectorEndpoint);
this.EnablePingTimer();
}
#pragma warning disable CA1031
catch (Exception e)
{
this.Log.LogError(e, "Init error");
this.Log.LogError(e, "Initialization error: {Message}", e.Message);
this.EnableInitTimer();
}
#pragma warning restore CA1031
Expand All @@ -461,7 +473,7 @@ public virtual async Task PingSemanticWorkbenchBackendAsync(CancellationToken ca
name = $"{this.WorkbenchConfig.ConnectorName} [{this.WorkbenchConfig.ConnectorId}]",
description = this.WorkbenchConfig.ConnectorDescription,
url = this.ConnectorEndpoint,
online_expires_in_seconds = 2 + (int)(PingFrequencyMS / 1000)
online_expires_in_seconds = 2 + (int)(PingFrequencyMsecs / 1000)
};

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

#region internals ===========================================================================

private const int PingFrequencyMS = 20000;
private const int PingFrequencyMsecs = 20000;

public void Dispose()
{
Expand Down
16 changes: 8 additions & 8 deletions tools/run-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ cd workbench-app

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

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

echo "Installing Node 20 via nvm..."
nvm install 20
nvm use 20
echo "Installing latest LTS Node version via nvm..."
nvm install --lts
nvm use --lts

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

0 comments on commit 256123e

Please sign in to comment.