35 lines
1.9 KiB
C#
35 lines
1.9 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Volcanic.AgenticCore.A2A.Server;
|
|
using Volcanic.AgenticCore.Extensions.A2A;
|
|
|
|
namespace Volcanic.AgenticCore.Telegram.A2A;
|
|
|
|
/// <summary>
|
|
/// The A2A client (off unless <c>A2AClient__Enabled=true</c>, independent of the server's <c>A2A__Enabled</c>). Only the
|
|
/// per-chat sessions get <see cref="A2AClientExtension"/> (<see cref="Chats.ChatRegistry"/>), never A2A server sessions.
|
|
/// Call before <see cref="TelegramA2ASetup.Register"/>, which copies the server options: when the server is on, its push
|
|
/// receiver is routed into the watch registry and its public URL becomes the push base URL. Call before the polling
|
|
/// service is registered too: hosted services start in order, and <see cref="A2AWatchHostedService"/> must point the
|
|
/// registry at the chats before the first chat session (else early results go through the registry's live-session
|
|
/// default).
|
|
/// </summary>
|
|
public static class TelegramA2AClientSetup
|
|
{
|
|
public static void Register(IServiceCollection services, A2AClientSettings client, A2AHostOptions server, A2AWatchRegistry registry)
|
|
{
|
|
// Only from the server: without its push receiver nobody would answer a push, so a configured value is ignored.
|
|
client.PushBaseUrl = server.Enabled && client.Enabled ? server.PublicUrl : null;
|
|
services.AddSingleton(client);
|
|
if (!client.Enabled) return;
|
|
if (server.Enabled) server.OnPush = registry.OnPushAsync;
|
|
services.AddSingleton(registry);
|
|
services.AddSingleton<TelegramA2AResultDelivery>();
|
|
services.AddHostedService<A2AWatchHostedService>();
|
|
}
|
|
|
|
public static string Describe(A2AClientSettings client) =>
|
|
client.Enabled
|
|
? $"A2A client: on, agents in each chat's .volcanic/a2a/agents.json, {(client.PushBaseUrl is null ? "watches subscribe or poll" : "push at " + client.PushBaseUrl)}"
|
|
: "A2A client: off";
|
|
}
|