Skip to content

Commit

Permalink
AgentClient - preparation for changes in the initialization process (#36
Browse files Browse the repository at this point in the history
)

This commit refactors the solution and prepares foundation for proper
initialization process:
- AgentConnector is now renamed to AgentClient
- IAgentClient is now renamed to IAgentService
- It's now possible to have more than one class with notification
handlers (e.g., one class for handling webview notifications and another
class for handling debug/message notifications)
- There's no longer a need to use a factory to create the agent client
- Warnings are now made useful again
- Eliminated the usage of libraries containing known vulnerabilities
- Removed unnecessary references from Cody.Core
- Replaced packages.config with PackageReference

Co-authored-by: Tomasz Gołębiowski <[email protected]>
  • Loading branch information
tomaszgolebiowski and Tomasz Gołębiowski authored Aug 13, 2024
1 parent 681c06c commit aec1d77
Show file tree
Hide file tree
Showing 29 changed files with 533 additions and 650 deletions.
9 changes: 4 additions & 5 deletions src/Cody.AgentTester/Cody.AgentTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@
<Project>{9ff2cc40-78e9-46c8-b2ef-30a1f1be82f2}</Project>
<Name>Cody.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StreamJsonRpc">
<Version>2.9.85</Version>
</PackageReference>
<ProjectReference Include="..\Cody.VisualStudio\Cody.VisualStudio.csproj">
<Project>{3bb34f98-f069-4a38-bc4d-cf407d59b863}</Project>
<Name>Cody.VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
27 changes: 15 additions & 12 deletions src/Cody.AgentTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
using Cody.Core.Agent;
using Cody.Core.Agent.Connector;
using Cody.Core.Agent.Protocol;
using Cody.VisualStudio.Client;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Cody.AgentTester
{
internal class Program
{
private static AgentConnector connector;
private static AgentClient client;
private static ConsoleLogger logger = new ConsoleLogger();
private static IAgentClient agentClient;
private static IAgentService agentService;

static async Task Main(string[] args)
{
// Set the env var to 3113 when running with local agent.
var portNumber = int.TryParse(Environment.GetEnvironmentVariable("CODY_VS_DEV_PORT"), out int port) ? port : (int?)null;
var devPort = Environment.GetEnvironmentVariable("CODY_VS_DEV_PORT");
var portNumber = int.TryParse(devPort, out int port) ? port : 3113;

var options = new AgentConnectorOptions
var options = new AgentClientOptions
{
NotificationsTarget = new NotificationHandlers(),
NotificationHandlers = new List<INotificationHandler> { new NotificationHandlers() },
AgentDirectory = "../../../Cody.VisualStudio/Agent",
RestartAgentOnFailure = true,
Debug = true,
Port = portNumber,
ConnectToRemoteAgent = devPort != null,
RemoteAgentPort = portNumber,
};

connector = new AgentConnector(options, logger);
client = new AgentClient(options, logger);

await connector.Connect();
client.Start();

agentClient = connector.CreateClient();
agentService = client.CreateAgentService<IAgentService>();

await Initialize();

Expand Down Expand Up @@ -76,9 +79,9 @@ private static async Task Initialize()
}
};

await agentClient.Initialize(clientInfo);
await agentService.Initialize(clientInfo);

agentClient.Initialized();
agentService.Initialized();
}


Expand Down
24 changes: 0 additions & 24 deletions src/Cody.Core/Agent/AgentClientFactory.cs

This file was deleted.

18 changes: 18 additions & 0 deletions src/Cody.Core/Agent/AgentMethodAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Agent
{
public class AgentMethodAttribute : Attribute
{
public AgentMethodAttribute(string name)
{
Name = name;
}

public string Name { get; private set; }
}
}
21 changes: 21 additions & 0 deletions src/Cody.Core/Agent/AgentNotificationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cody.Core.Agent
{
public class AgentNotificationAttribute : Attribute
{
public AgentNotificationAttribute(string name, bool deserializeToSingleObject = false)
{
Name = name;
DeserializeToSingleObject = deserializeToSingleObject;
}

public string Name { get; private set; }

public bool DeserializeToSingleObject { get; private set; }
}
}
108 changes: 0 additions & 108 deletions src/Cody.Core/Agent/Connector/AgentConnector.cs

This file was deleted.

28 changes: 0 additions & 28 deletions src/Cody.Core/Agent/Connector/AgentConnectorOptions.cs

This file was deleted.

Loading

0 comments on commit aec1d77

Please sign in to comment.