diff --git a/VolcanicAgenticCore.slnx b/VolcanicAgenticCore.slnx index 0a30abf..7231bbf 100644 --- a/VolcanicAgenticCore.slnx +++ b/VolcanicAgenticCore.slnx @@ -12,6 +12,7 @@ + diff --git a/samples/Volcanic.AgenticCore.Sample.A2A/Program.cs b/samples/Volcanic.AgenticCore.Sample.A2A/Program.cs new file mode 100644 index 0000000..d6365c4 --- /dev/null +++ b/samples/Volcanic.AgenticCore.Sample.A2A/Program.cs @@ -0,0 +1,50 @@ +// Minimal standalone A2A server over one workspace. +// +// dotnet run --project samples/Volcanic.AgenticCore.Sample.A2A -- --faux --workspace /tmp/ws +// (callers in /tmp/ws/.volcanic/a2a/callers.json; card at http://localhost:5000/.well-known/agent-card.json) + +using Microsoft.Extensions.Logging; +using Volcanic.AgenticCore.A2A.Server.Callers; +using Volcanic.AgenticCore.A2A.Server.Hosting; +using Volcanic.AgenticCore.Extensions.ClaudeCode; +using Volcanic.AgenticCore.Features.Extensions; +using Volcanic.AgenticCore.Hosting; +using Volcanic.AgenticCore.Testing; + +var faux = args.Contains("--faux"); +var workspaceIndex = Array.IndexOf(args, "--workspace"); +var workspace = Path.GetFullPath(workspaceIndex >= 0 && workspaceIndex + 1 < args.Length ? args[workspaceIndex + 1] : Directory.GetCurrentDirectory()); + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddAgenticCore(o => +{ + if (faux) + { + var provider = new FauxProvider(); + o.Extensions.Add(ExtensionRegistration.FromInstance(provider.Extension)); + o.DefaultModel = FauxProvider.ModelKey; + } + else + { + o.AddExtension(); + o.DefaultModel ??= "claude-code/sonnet"; + } +}); +builder.Services.AddSingleton(sp => new WorkspaceCallerDirectory( + () => [new A2AWorkspace(workspace, "sample", "sample")], sp.GetRequiredService>())); +builder.Services.AddSingleton(); +builder.Services.AddA2AServer(o => builder.Configuration.GetSection(Volcanic.AgenticCore.A2A.Server.A2AHostOptions.SectionName).Bind(o)); + +var app = builder.Build(); +app.MapA2AServer(); +app.Logger.LogInformation("A2A sample serving workspace {Workspace}; callers in {File}", workspace, CallersFile.PathFor(workspace)); +app.Run(); + +internal sealed class LogNotifier(ILogger logger) : IA2AOwnerNotifier +{ + public Task NotifyAsync(A2ACaller caller, string text, CancellationToken cancellationToken) + { + logger.LogInformation("notify_owner from {Caller}: {Text}", caller.Name, text); + return Task.CompletedTask; + } +} diff --git a/samples/Volcanic.AgenticCore.Sample.A2A/Volcanic.AgenticCore.Sample.A2A.csproj b/samples/Volcanic.AgenticCore.Sample.A2A/Volcanic.AgenticCore.Sample.A2A.csproj new file mode 100644 index 0000000..3eb1964 --- /dev/null +++ b/samples/Volcanic.AgenticCore.Sample.A2A/Volcanic.AgenticCore.Sample.A2A.csproj @@ -0,0 +1,6 @@ + + + + + +