c8d9af6191
Autonomous agents with MCP tools now run a bounded tool-use loop: the model may call tools (executed via the gateway, results fed back) until it returns a final answer. Gated/DraftOnly agents get the tool catalog as data but never auto-call — a human-in-the-loop agent never autonomously reaches an external tool. Extends IModelClient with tool definitions and a tool-use conversation, adds the OpenAI-compatible tool serialization/parsing plus a deterministic "tooluse" stub client, and records every tool call in the run trace. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
64 lines
2.9 KiB
C#
64 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using TeamUp.Modules.Integrations.Ai;
|
|
using TeamUp.Modules.Integrations.Endpoints;
|
|
using TeamUp.Modules.Integrations.Git;
|
|
using TeamUp.Modules.Integrations.Persistence;
|
|
using TeamUp.Modules.Integrations.Security;
|
|
using TeamUp.SharedKernel.Ai;
|
|
using TeamUp.SharedKernel.Git;
|
|
using TeamUp.SharedKernel.Modularity;
|
|
using TeamUp.SharedKernel.Persistence;
|
|
|
|
namespace TeamUp.Modules.Integrations;
|
|
|
|
/// <summary>
|
|
/// BYOK API configs (encrypted, owner-only), the model-client adapters, and the Git connection.
|
|
/// Encryption keys are owner-only and server-side; the decrypted key never leaves the server.
|
|
/// </summary>
|
|
public sealed class IntegrationsModule : IModule
|
|
{
|
|
public string Name => "integrations";
|
|
|
|
public void Register(IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var connectionString = configuration.GetConnectionString("Postgres")
|
|
?? throw new InvalidOperationException("Missing connection string 'ConnectionStrings:Postgres'.");
|
|
|
|
// BYOK credential store + encryption.
|
|
services.AddDbContext<IntegrationsDbContext>(options => options.UseNpgsql(connectionString));
|
|
services.AddScoped<IModuleDbContext>(sp => sp.GetRequiredService<IntegrationsDbContext>());
|
|
services.Configure<EncryptionOptions>(configuration.GetSection(EncryptionOptions.SectionName));
|
|
services.AddSingleton<ISecretProtector, AesGcmSecretProtector>();
|
|
services.AddScoped<IApiConfigResolver, ApiConfigResolver>();
|
|
services.TryAddSingleton(TimeProvider.System);
|
|
|
|
// Model clients: a router over per-provider adapters.
|
|
services.AddSingleton<StubModelClient>();
|
|
services.AddSingleton<ToolUseStubModelClient>();
|
|
services.AddHttpClient<OpenAiCompatibleModelClient>();
|
|
services.AddScoped<IModelClient, ModelClientRouter>();
|
|
|
|
// MCP: a JSON-RPC client over HTTP + the org-scoped gateway agents talk through.
|
|
services.AddHttpClient<Mcp.McpClient>();
|
|
services.AddScoped<IMcpGateway, Mcp.McpGateway>();
|
|
|
|
// Git source (M2) — filesystem for dogfood, Gitea over REST when configured.
|
|
services.Configure<GitSourceOptions>(configuration.GetSection(GitSourceOptions.SectionName));
|
|
var gitOptions = configuration.GetSection(GitSourceOptions.SectionName).Get<GitSourceOptions>() ?? new GitSourceOptions();
|
|
if (string.Equals(gitOptions.Provider, "gitea", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
services.AddHttpClient<IGitProvider, GiteaGitProvider>();
|
|
}
|
|
else
|
|
{
|
|
services.AddSingleton<IGitProvider, FileSystemGitProvider>();
|
|
}
|
|
}
|
|
|
|
public void MapEndpoints(IEndpointRouteBuilder endpoints) => IntegrationsEndpoints.Map(endpoints);
|
|
}
|