You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using Azure.Identity;
  4. using DevTeam.Backend;
  5. using DevTeam.Options;
  6. using Microsoft.AI.DevTeam;
  7. using Microsoft.AutoGen.Core;
  8. using Microsoft.AutoGen.Extensions.SemanticKernel;
  9. using Microsoft.Extensions.Azure;
  10. using Microsoft.Extensions.Options;
  11. using Octokit.Webhooks;
  12. using Octokit.Webhooks.AspNetCore;
  13. var builder = WebApplication.CreateBuilder(args);
  14. builder.AddServiceDefaults();
  15. builder.ConfigureSemanticKernel();
  16. builder.Services.AddHttpClient();
  17. builder.Services.AddControllers();
  18. builder.Services.AddSwaggerGen();
  19. builder.AddAgentWorker(builder.Configuration["AGENT_HOST"]!)
  20. .AddAgent<AzureGenie>(nameof(AzureGenie))
  21. //.AddAgent<Sandbox>(nameof(Sandbox))
  22. .AddAgent<Hubber>(nameof(Hubber));
  23. builder.Services.AddSingleton<AgentWorker>();
  24. builder.Services.AddSingleton<WebhookEventProcessor, GithubWebHookProcessor>();
  25. builder.Services.AddSingleton<GithubAuthService>();
  26. builder.Services.AddSingleton<IManageAzure, AzureService>();
  27. builder.Services.AddSingleton<IManageGithub, GithubService>();
  28. builder.Services.AddTransient(s =>
  29. {
  30. var ghOptions = s.GetRequiredService<IOptions<GithubOptions>>();
  31. var logger = s.GetRequiredService<ILogger<GithubAuthService>>();
  32. var ghService = new GithubAuthService(ghOptions, logger);
  33. var client = ghService.GetGitHubClient();
  34. return client;
  35. });
  36. // TODO: Rework?
  37. builder.Services.AddOptions<GithubOptions>()
  38. .Configure<IConfiguration>((settings, configuration) =>
  39. {
  40. configuration.GetSection("Github").Bind(settings);
  41. })
  42. .ValidateDataAnnotations()
  43. .ValidateOnStart();
  44. builder.Services.AddAzureClients(clientBuilder =>
  45. {
  46. clientBuilder.AddArmClient(default);
  47. clientBuilder.UseCredential(new DefaultAzureCredential());
  48. });
  49. var app = builder.Build();
  50. app.MapDefaultEndpoints();
  51. app.UseRouting()
  52. .UseEndpoints(endpoints =>
  53. {
  54. var ghOptions = app.Services.GetRequiredService<IOptions<GithubOptions>>().Value;
  55. endpoints.MapGitHubWebhooks(secret: ghOptions.WebhookSecret);
  56. }); ;
  57. app.UseSwagger();
  58. /* app.UseSwaggerUI(c =>
  59. {
  60. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  61. }); */
  62. app.Run();