Table of Contents

Class GatewayConnectionService

Namespace
JD.AI.Services
Assembly
JD.AI.dll

Manages TUI connection to a running Gateway instance. When connected, agent execution is delegated to Gateway instead of running in-process.

public sealed class GatewayConnectionService : IAsyncDisposable
Inheritance
GatewayConnectionService
Implements
Inherited Members

Constructors

GatewayConnectionService(string)

public GatewayConnectionService(string gatewayUrl)

Parameters

gatewayUrl string

Properties

ActiveAgentId

public string? ActiveAgentId { get; }

Property Value

string

GatewayUrl

public string GatewayUrl { get; }

Property Value

string

IsConnected

public bool IsConnected { get; }

Property Value

bool

Methods

ConnectAsync(CancellationToken)

Connect to Gateway and verify it's running.

public Task<bool> ConnectAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task<bool>

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

EnsureAgentAsync(string?, string?, CancellationToken)

Get or spawn an agent, returning its ID.

public Task<string?> EnsureAgentAsync(string? provider = null, string? model = null, CancellationToken ct = default)

Parameters

provider string
model string
ct CancellationToken

Returns

Task<string>

GetLatestSessionAsync(CancellationToken)

Returns the most recent persisted session ID, or null when none exist.

public Task<string?> GetLatestSessionAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task<string>

GetProvidersAsync(CancellationToken)

Get available providers.

public Task<ProviderInfo[]> GetProvidersAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task<ProviderInfo[]>

GetSessionsAsync(int, CancellationToken)

Get sessions list.

public Task<SessionInfo[]> GetSessionsAsync(int limit = 50, CancellationToken ct = default)

Parameters

limit int
ct CancellationToken

Returns

Task<SessionInfo[]>

GetStatusAsync(CancellationToken)

Get Gateway status summary.

public Task<GatewayStatus?> GetStatusAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task<GatewayStatus>

PrintStatus()

Print connection status to console.

public void PrintStatus()

SendMessageAsync(string, CancellationToken)

Send a message and get the full response (non-streaming).

public Task<string?> SendMessageAsync(string message, CancellationToken ct = default)

Parameters

message string
ct CancellationToken

Returns

Task<string>

SendMessageStreamingAsync(string, CancellationToken)

Send a message and stream the response.

public IAsyncEnumerable<string> SendMessageStreamingAsync(string message, CancellationToken ct = default)

Parameters

message string
ct CancellationToken

Returns

IAsyncEnumerable<string>