17 | Welcome to the AI Red Teaming Playground Labs. You will find below the challenges that are available. You can try a challenge and come back here once the challenge is completed.
18 |
19 |
20 |
21 |
22 | );
23 | }
24 |
25 | export default App;
26 |
--------------------------------------------------------------------------------
/src/challenge-home/webapp/src/index.tsx:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | import { FluentProvider, teamsLightTheme } from '@fluentui/react-components';
5 |
6 | import App from './App';
7 |
8 | import './App.css';
9 |
10 | import { createRoot } from 'react-dom/client';
11 | const container = document.getElementById('root');
12 | const root = createRoot(container!);
13 |
14 | root.render(
15 |
16 |
17 |
18 | )
--------------------------------------------------------------------------------
/src/challenge-home/webapp/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | ///
5 |
--------------------------------------------------------------------------------
/src/challenge-home/webapp/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "noFallthroughCasesInSwitch": true,
16 | "module": "esnext",
17 | "moduleResolution": "node",
18 | "resolveJsonModule": true,
19 | "isolatedModules": true,
20 | "noEmit": true,
21 | "jsx": "react-jsx"
22 | },
23 | "include": [
24 | "src"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/http-plugin/HttpPlugin.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 | true
12 | $(NoWarn);1591
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | PreserveNewest
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/http-plugin/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Reflection;
5 | using Microsoft.OpenApi.Models;
6 |
7 | var builder = WebApplication.CreateBuilder(args);
8 |
9 | // Add services to the container.
10 |
11 | builder.Services.AddControllers();
12 | builder.Services.AddHttpLogging(o => { });
13 |
14 |
15 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
16 | builder.Services.AddEndpointsApiExplorer();
17 | builder.Services.AddSwaggerGen(options =>
18 | {
19 | options.SwaggerDoc("v1", new OpenApiInfo
20 | {
21 | Title = "Http Request",
22 | Description = "Make an HTTP GET request to the specified URI.",
23 | Version = "v1",
24 | });
25 |
26 | var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
27 | options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
28 | });
29 |
30 |
31 |
32 | builder.Services.AddHttpClient("httpClient").ConfigurePrimaryHttpMessageHandler(() =>
33 | {
34 | return new HttpClientHandler()
35 | {
36 | AllowAutoRedirect = false
37 | };
38 | }); ;
39 |
40 | var app = builder.Build();
41 | app.UseHttpLogging();
42 | app.UseSwagger();
43 | app.UseSwaggerUI();
44 | app.UseStaticFiles();
45 |
46 | app.UseAuthorization();
47 |
48 | app.MapControllers();
49 |
50 | app.Run();
51 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/http-plugin/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning",
6 | "Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/http-plugin/wwwroot/.well-known/ai-plugin.json:
--------------------------------------------------------------------------------
1 | {
2 | "schema_version": "v1",
3 | "name_for_human": "Http Request",
4 | "name_for_model": "HttpRequest",
5 | "description_for_human": "Use this plugin to enable users make HTTP GET requests to websites.",
6 | "description_for_model": "Use this plugin to enable users make HTTP GET requests to websites. This plugin should only be used if the user passes in a URL to the model.",
7 | "auth": {
8 | "type": "none"
9 | },
10 | "api": {
11 | "type": "openapi",
12 | "url": "http://localhost:5084/swagger/v1/swagger.json"
13 | },
14 | "logo_url": "https://example.com/logo.png",
15 | "contact_email": "support@example.com",
16 | "legal_info_url": "http://www.example.com/legal"
17 | }
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/rce-plugin/flag.txt:
--------------------------------------------------------------------------------
1 | FLAG-c0n741n3r5_5h0uld_b3_54ndb0x3d_pr0p3rly
2 |
3 | Good job! You have found the first flag.
4 | In order to fully complete this challenge, you need to move laterally to another code running container and extract it's flag.
5 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/rce-plugin/requirements.txt:
--------------------------------------------------------------------------------
1 | blinker==1.7.0
2 | click==8.1.7
3 | colorama==0.4.6
4 | Flask==3.0.0
5 | itsdangerous==2.1.2
6 | Jinja2==3.1.3
7 | MarkupSafe==2.1.3
8 | Werkzeug==3.0.1
9 |
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/rce-plugin/static/.well-known/ai-plugin.json:
--------------------------------------------------------------------------------
1 | {
2 | "schema_version": "v1",
3 | "name_for_human": "Python Code Runner",
4 | "name_for_model": "Python Code Runner",
5 | "description_for_human": "Use this plugin to run Python code. The plugin will run the python code and answer with the output of the python code.",
6 | "description_for_model": "Use this plugin to run Python code. The plugin will run the python code and answer with the output of the python code.",
7 | "auth": {
8 | "type": "none"
9 | },
10 | "api": {
11 | "type": "openapi",
12 | "url": "http://localhost:5000/swagger/swagger.json"
13 | },
14 | "logo_url": "https://example.com/logo.png",
15 | "contact_email": "support@example.com",
16 | "legal_info_url": "http://www.example.com/legal"
17 | }
--------------------------------------------------------------------------------
/src/chat-copilot/plugins/rce-plugin/static/swagger/swagger.json:
--------------------------------------------------------------------------------
1 | {
2 | "openapi": "3.0.1",
3 | "info": {
4 | "title": "Python Code Runner",
5 | "description": "Run Python code and return the output of the code.",
6 | "version": "v1"
7 | },
8 | "paths": {
9 | "/execute": {
10 | "post": {
11 | "tags": [
12 | "Http"
13 | ],
14 | "summary": "Run Python code and return the output of the code.",
15 | "operationId": "RunCode",
16 | "requestBody": {
17 | "description": "The python code should be in the body",
18 | "content": {
19 | "text/plain": {
20 | "schema": {
21 | "type": "string"
22 | }
23 | }
24 | }
25 | },
26 | "responses": {
27 | "200": {
28 | "description": "Returns the response from the code",
29 | "content": {
30 | "text/plain": {
31 | "schema": {
32 | "type": "string"
33 | }
34 | }
35 | }
36 | }
37 | }
38 | }
39 | }
40 | },
41 | "components": {}
42 | }
--------------------------------------------------------------------------------
/src/chat-copilot/shared/CopilotChatShared.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CopilotChat.Shared
5 | net6.0
6 | LatestMajor
7 | disable
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/chat-copilot/shared/MemoryClientBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using CopilotChat.Shared.Ocr;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.DependencyInjection;
8 | using Microsoft.KernelMemory;
9 |
10 | namespace CopilotChat.Shared;
11 |
12 | ///
13 | /// Dependency injection for kernel memory using custom OCR configuration defined in appsettings.json
14 | ///
15 | public static class MemoryClientBuilderExtensions
16 | {
17 | public static KernelMemoryBuilder WithCustomOcr(this KernelMemoryBuilder builder, IServiceProvider sp, IConfiguration configuration)
18 | {
19 | var ocrEngine = configuration.CreateCustomOcr(sp);
20 |
21 | if (ocrEngine != null)
22 | {
23 | builder.WithCustomImageOcr(ocrEngine);
24 | }
25 |
26 | return builder;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/chat-copilot/shared/MemoryConfiguration.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.Shared;
5 |
6 | ///
7 | /// Configuration constants for kernel memory.
8 | ///
9 | public static class MemoryConfiguration
10 | {
11 | public const string KernelMemorySection = "KernelMemory";
12 | public const string ServicesSection = "Services";
13 | public const string OrchestrationTypeDistributed = "Distributed";
14 | public const string NoneType = "None";
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/shared/Ocr/Tesseract/TesseractOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.ComponentModel.DataAnnotations;
5 |
6 | namespace CopilotChat.Shared.Ocr.Tesseract;
7 |
8 | ///
9 | /// Configuration options for Tesseract OCR support.
10 | ///
11 | public sealed class TesseractOptions
12 | {
13 | public const string SectionName = "Tesseract";
14 |
15 | ///
16 | /// The file path where the Tesseract language file is stored (e.g. "./data")
17 | ///
18 | [Required]
19 | public string? FilePath { get; set; } = string.Empty;
20 |
21 | ///
22 | /// The language file prefix name (e.g. "eng")
23 | ///
24 | [Required]
25 | public string? Language { get; set; } = string.Empty;
26 | }
27 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Auth/AuthPolicyName.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Auth;
5 |
6 | ///
7 | /// Holds the policy names for custom authorization policies.
8 | ///
9 | public static class AuthPolicyName
10 | {
11 | public const string RequireChatParticipant = "RequireChatParticipant";
12 | }
13 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Auth/AuthType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Auth;
5 |
6 | ///
7 | /// Types of authentication used in the system.
8 | ///
9 | public enum AuthType
10 | {
11 | ///
12 | /// No authentication is required. The user is assigned a GUID in the cookie and is identified by that.
13 | ///
14 | None,
15 |
16 | ///
17 | /// Authentication is performed by CTFd. The platform validates the CTFd cookie and checks with the CTFd redis instance if the session exists.
18 | ///
19 | CTFd,
20 |
21 | ///
22 | /// Authentication is performed by the challenge home service. The cookie is validated by the instance.
23 | ///
24 | ChallengeHome
25 | }
26 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Auth/AuthzChallengeEnum.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Auth;
5 |
6 | public static class AuthzChallenge
7 | {
8 | ///
9 | /// Allows a user to upload files to the chat
10 | ///
11 | public const string Upload = "upload";
12 |
13 | ///
14 | /// Allows a user to enable/disable plugins in chats
15 | ///
16 | public const string PluginsControl = "pluginsControl";
17 |
18 | ///
19 | /// Allows a user to interact with plugins. This flag is controlled by the plugins array
20 | ///
21 | public const string Plugins = "plugins";
22 |
23 | ///
24 | /// Allows a user to use the human scorer
25 | ///
26 | public const string HumanScorer = "humanScorer";
27 |
28 | ///
29 | /// Allows the user to make a request to the XSS vulnreable endpoint to see the scoring message
30 | ///
31 | public const string XssVulnerable = "xssVulnerable";
32 |
33 | public const string RagInput = "ragInput";
34 | }
35 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Auth/ChatParticipantRequirement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using Microsoft.AspNetCore.Authorization;
5 |
6 | namespace CopilotChat.WebApi.Auth;
7 |
8 | ///
9 | /// Used to require the chat to be owned by the authenticated user.
10 | ///
11 | public class ChatParticipantRequirement : IAuthorizationRequirement
12 | {
13 | }
14 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Auth/IAuthInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Auth;
5 |
6 | public interface IAuthInfo
7 | {
8 | ///
9 | /// The authenticated user's unique ID.
10 | ///
11 | public string UserId { get; }
12 |
13 | ///
14 | /// The authenticated user's name.
15 | ///
16 | public string Name { get; }
17 | }
18 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Extensions/ExceptionExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Threading;
5 |
6 | #pragma warning disable IDE0130
7 | // ReSharper disable once CheckNamespace - Using NS of Exception
8 | namespace System;
9 | #pragma warning restore IDE0130
10 |
11 | ///
12 | /// Exception extension methods.
13 | ///
14 | internal static class ExceptionExtensions
15 | {
16 | ///
17 | /// Check if an exception is of a type that should not be caught by the kernel.
18 | ///
19 | /// Exception.
20 | /// True if is a critical exception and should not be caught.
21 | internal static bool IsCriticalException(this Exception ex)
22 | => ex is OutOfMemoryException
23 | or ThreadAbortException
24 | or AccessViolationException
25 | or AppDomainUnloadedException
26 | or BadImageFormatException
27 | or CannotUnloadAppDomainException
28 | or InvalidProgramException
29 | or StackOverflowException;
30 | }
31 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Extensions/IAsyncEnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Threading.Tasks;
6 |
7 | namespace CopilotChat.WebApi.Extensions;
8 |
9 | ///
10 | /// Extension methods for enabling async LINQ operations on IAsyncEnumerable sequence.
11 | ///
12 | public static class IAsyncEnumerableExtensions
13 | {
14 | ///
15 | /// Creates a List from an IAsyncEnumerable by enumerating it asynchronously.
16 | ///
17 | internal static async Task> ToListAsync(this IAsyncEnumerable source)
18 | {
19 | var result = new List();
20 | await foreach (var item in source)
21 | {
22 | result.Add(item);
23 | }
24 |
25 | return result;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/Ask.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.ComponentModel.DataAnnotations;
6 | using System.Linq;
7 | using CopilotChat.WebApi.Options;
8 |
9 | namespace CopilotChat.WebApi.Models.Request;
10 |
11 | public class Ask
12 | {
13 | [Required, NotEmptyOrWhitespace]
14 | public string Input { get; set; } = string.Empty;
15 |
16 | public IEnumerable> Variables { get; set; } = Enumerable.Empty>();
17 | }
18 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/CreateChatParameters.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 | using System.Text.Json.Serialization;
4 |
5 | namespace CopilotChat.WebApi.Models.Request;
6 |
7 | ///
8 | /// Parameters for creating a new chat session.
9 | ///
10 | public class CreateChatParameters
11 | {
12 | ///
13 | /// Title of the chat.
14 | ///
15 | [JsonPropertyName("title")]
16 | public string? Title { get; set; }
17 | }
18 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/CtfdFlagSubmission.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Request;
7 |
8 | public class CtfdFlagSubmission
9 | {
10 | [JsonPropertyName("challenge_id")]
11 | public int ChallengeId { get; set; } = 0;
12 |
13 | [JsonPropertyName("submission")]
14 | public string Submission { get; set; } = string.Empty;
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/CustomPlugin.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 | using System.Text.Json.Serialization;
4 |
5 | namespace CopilotChat.WebApi.Models.Request;
6 |
7 | ///
8 | /// Custom plugin imported from ChatGPT Manifest file.
9 | /// Docs: https://platform.openai.com/docs/plugins/introduction.
10 | ///
11 | public class CustomPlugin
12 | {
13 | ///
14 | /// Human-readable name, such as the full company name.
15 | ///
16 | [JsonPropertyName("nameForHuman")]
17 | public string NameForHuman { get; set; } = string.Empty;
18 |
19 | ///
20 | /// Name the model will use to target the plugin.
21 | ///
22 | [JsonPropertyName("nameForModel")]
23 | public string NameForModel { get; set; } = string.Empty;
24 |
25 | ///
26 | /// Expected request header tag containing auth information.
27 | ///
28 | [JsonPropertyName("authHeaderTag")]
29 | public string AuthHeaderTag { get; set; } = string.Empty;
30 |
31 | ///
32 | /// Auth type. Currently limited to either 'none'
33 | /// or user PAT (https://platform.openai.com/docs/plugins/authentication/user-level)
34 | ///
35 | [JsonPropertyName("authType")]
36 | public string AuthType { get; set; } = string.Empty;
37 |
38 | ///
39 | /// Website domain hosting the plugin files.
40 | ///
41 | [JsonPropertyName("manifestDomain")]
42 | public string ManifestDomain { get; set; } = string.Empty;
43 | }
44 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/DocumentData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Request;
7 |
8 | public sealed class DocumentData
9 | {
10 | ///
11 | /// Name of the uploaded document.
12 | ///
13 | [JsonPropertyName("name")]
14 | public string Name { get; set; } = string.Empty;
15 |
16 | ///
17 | /// Size of the uploaded document in bytes.
18 | ///
19 | [JsonPropertyName("size")]
20 | public string Size { get; set; } = string.Empty;
21 |
22 | ///
23 | /// Status of the uploaded document.
24 | /// If true, the document is successfully uploaded. False otherwise.
25 | ///
26 | [JsonPropertyName("isUploaded")]
27 | public bool IsUploaded { get; set; } = false;
28 | }
29 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/DocumentImportForm.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using Microsoft.AspNetCore.Http;
7 |
8 | namespace CopilotChat.WebApi.Models.Request;
9 |
10 | ///
11 | /// Form for importing a document from a POST Http request.
12 | ///
13 | public class DocumentImportForm
14 | {
15 | ///
16 | /// The file to import.
17 | ///
18 | public IEnumerable FormFiles { get; set; } = Enumerable.Empty();
19 |
20 | ///
21 | /// Flag indicating whether user has content safety enabled from the client.
22 | ///
23 | public bool UseContentSafety { get; set; } = false;
24 | }
25 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/DocumentScopes.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Request;
5 |
6 | ///
7 | /// Scope of the document. This determines the collection name in the document memory.
8 | ///
9 | public enum DocumentScopes
10 | {
11 | Global,
12 | Chat,
13 | }
14 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/EditChatParameters.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Request;
5 |
6 | ///
7 | /// Parameters for editing chat session.
8 | ///
9 | public class EditChatParameters
10 | {
11 | ///
12 | /// Title of the chat.
13 | ///
14 | public string? Title { get; set; }
15 |
16 | ///
17 | /// System description of the chat that is used to generate responses.
18 | ///
19 | public string? SystemDescription { get; set; }
20 |
21 | ///
22 | /// The balance between long term memory and working term memory.
23 | /// The higher this value, the more the system will rely on long term memory by lowering
24 | /// the relevance threshold of long term memory and increasing the threshold score of working memory.
25 | ///
26 | public float? MemoryBalance { get; set; }
27 | }
28 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/ExecutePlanParameters.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using CopilotChat.WebApi.Models.Response;
5 |
6 | namespace CopilotChat.WebApi.Models.Request;
7 |
8 | public class ExecutePlanParameters : Ask
9 | {
10 | public ProposedPlan? Plan { get; set; }
11 | }
12 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/ManualScoring.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Request;
7 |
8 | public class ManualScoring
9 | {
10 | [JsonPropertyName("chatId")]
11 | public string ChatId { get; set; } = string.Empty;
12 |
13 | [JsonPropertyName("messageIndex")]
14 | public int MessageIndex { get; set; } = 0;
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/RagInput.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Request;
7 |
8 | public class RagInput
9 | {
10 | [JsonPropertyName("document")]
11 | public string? Document { get; set; }
12 |
13 | [JsonPropertyName("userInput")]
14 | public string? UserInput { get; set; }
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/ScoringIntake.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text.Json.Serialization;
7 |
8 | namespace CopilotChat.WebApi.Models.Request;
9 |
10 | public class ScoringIntake
11 | {
12 | [JsonPropertyName("challenge_id")]
13 | public int ChallengeId { get; set; } = 0;
14 |
15 | [JsonPropertyName("challenge_goal")]
16 | public string Goal { get; set; } = string.Empty;
17 |
18 | [JsonPropertyName("challenge_title")]
19 | public string Title { get; set; } = string.Empty;
20 |
21 | [JsonPropertyName("conversation")]
22 | public IEnumerable? Conversation { get; set; }
23 |
24 | [JsonPropertyName("timestamp")]
25 | public DateTime Timestamp { get; set; }
26 |
27 | [JsonPropertyName("conversation_id")]
28 | public Guid ChatId { get; set; } = Guid.Empty;
29 |
30 | [JsonPropertyName("document")]
31 | public string Document { get; set; } = string.Empty;
32 |
33 | [JsonPropertyName("answer_uri")]
34 | public string AnswerUri { get; set; } = string.Empty;
35 |
36 | public class ScoringIntakeMessage
37 | {
38 | [JsonPropertyName("message")]
39 | public string Message { get; set; } = string.Empty;
40 |
41 | [JsonPropertyName("role")]
42 | public int Role { get; set; } = 0;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Request/SemanticMemoryType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Request;
5 |
6 | ///
7 | /// Types of semantic memories supported by chat-copilot.
8 | ///
9 | public enum SemanticMemoryType
10 | {
11 | LongTermMemory,
12 | WorkingMemory
13 | }
14 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/AskResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | namespace CopilotChat.WebApi.Models.Response;
8 |
9 | public class AskResult
10 | {
11 | public string Value { get; set; } = string.Empty;
12 |
13 | public IEnumerable>? Variables { get; set; } = Enumerable.Empty>();
14 | }
15 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/AuthErrorResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public class AuthErrorResponse
9 | {
10 | [JsonPropertyName("auth_type")]
11 | public string AuthType { get; set; } = string.Empty;
12 |
13 | [JsonPropertyName("error")]
14 | public string Error { get; set; } = string.Empty;
15 |
16 | [JsonPropertyName("redirect_uri")]
17 | public string RedirectUri { get; set; } = string.Empty;
18 | }
19 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/ChatArchiveEmbeddingConfig.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.ComponentModel.DataAnnotations;
5 | using System.Text.Json.Serialization;
6 |
7 | namespace CopilotChat.WebApi.Models.Response;
8 |
9 | ///
10 | /// Chat archive embedding configuration.
11 | ///
12 | public class ChatArchiveEmbeddingConfig
13 | {
14 | ///
15 | /// Supported types of AI services.
16 | ///
17 | public enum AIServiceType
18 | {
19 | ///
20 | /// Azure OpenAI https://learn.microsoft.com/en-us/azure/cognitive-services/openai/
21 | ///
22 | AzureOpenAIEmbedding,
23 |
24 | ///
25 | /// OpenAI https://openai.com/
26 | ///
27 | OpenAI
28 | }
29 |
30 | ///
31 | /// The AI service.
32 | ///
33 | [Required]
34 | [JsonConverter(typeof(JsonStringEnumConverter))]
35 | public AIServiceType AIService { get; set; } = AIServiceType.AzureOpenAIEmbedding;
36 |
37 | ///
38 | /// The deployment or the model id.
39 | ///
40 | public string DeploymentOrModelId { get; set; } = string.Empty;
41 | }
42 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/CreateChatResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 | using CopilotChat.WebApi.Models.Storage;
6 |
7 | namespace CopilotChat.WebApi.Models.Response;
8 |
9 | ///
10 | /// Response object definition to the 'chats' POST request.
11 | /// This groups the initial bot message with the chat session
12 | /// to avoid making two requests.
13 | ///
14 | public class CreateChatResponse
15 | {
16 | ///
17 | /// The chat session that was created.
18 | ///
19 | [JsonPropertyName("chatSession")]
20 | public ChatSession ChatSession { get; set; }
21 |
22 | ///
23 | /// Initial bot message.
24 | ///
25 | [JsonPropertyName("initialBotMessage")]
26 | public CopilotChatMessage InitialBotMessage { get; set; }
27 |
28 | public CreateChatResponse(ChatSession chatSession, CopilotChatMessage initialBotMessage)
29 | {
30 | this.ChatSession = chatSession;
31 | this.InitialBotMessage = initialBotMessage;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/CtfdChallengeResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public class CtfdChallengeResponse
9 | {
10 | [JsonPropertyName("name")]
11 | public string Name { get; set; } = string.Empty;
12 |
13 | [JsonPropertyName("id")]
14 | public int Id { get; set; } = 0;
15 |
16 | [JsonPropertyName("value")]
17 | public int Value { get; set; } = 0;
18 |
19 | [JsonPropertyName("solved_by_me")]
20 | public bool SolvedByMe { get; set; } = false;
21 | }
22 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/CtfdFlagSubmissionResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public class CtfdFlagSubmissionResponse
9 | {
10 | [JsonPropertyName("status")]
11 | public string Status { get; set; } = string.Empty;
12 |
13 | [JsonPropertyName("message")]
14 | public string Message { get; set; } = string.Empty;
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/CtfdResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public class CtfdResponse where T : class
9 | {
10 | [JsonPropertyName("success")]
11 | public bool Success { get; set; }
12 |
13 | [JsonPropertyName("data")]
14 | public T Data { get; set; } = default!;
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/FrontendAuthConfig.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 | using CopilotChat.WebApi.Options;
6 |
7 | namespace CopilotChat.WebApi.Models.Response;
8 |
9 | ///
10 | /// Configuration to be used by the frontend client to this service.
11 | ///
12 | public class FrontendAuthConfig
13 | {
14 | ///
15 | /// Type of auth to use.
16 | ///
17 | [JsonPropertyName("authType")]
18 | public string AuthType { get; set; } = ChatAuthenticationOptions.AuthenticationType.None.ToString();
19 |
20 | ///
21 | /// Azure Active Directory authority to use.
22 | ///
23 | [JsonPropertyName("aadAuthority")]
24 | public string AadAuthority { get; set; } = string.Empty;
25 |
26 | ///
27 | /// Azure Active Directory client ID the frontend is to use.
28 | ///
29 | [JsonPropertyName("aadClientId")]
30 | public string AadClientId { get; set; } = string.Empty;
31 |
32 | ///
33 | /// Azure Active Directory scope the frontend should request.
34 | ///
35 | [JsonPropertyName("aadApiScope")]
36 | public string AadApiScope { get; set; } = string.Empty;
37 | }
38 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/ImageAnalysisResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 | using CopilotChat.WebApi.Services;
6 |
7 | namespace CopilotChat.WebApi.Models.Response;
8 |
9 | ///
10 | /// Response definition to image content safety analysis requests.
11 | /// endpoint made by the AzureContentSafety.
12 | ///
13 | public class ImageAnalysisResponse
14 | {
15 | ///
16 | /// Gets or sets the AnalysisResult related to hate.
17 | ///
18 | [JsonPropertyName("hateResult")]
19 | public AnalysisResult? HateResult { get; set; }
20 |
21 | ///
22 | /// Gets or sets the AnalysisResult related to self-harm.
23 | ///
24 | [JsonPropertyName("selfHarmResult")]
25 | public AnalysisResult? SelfHarmResult { get; set; }
26 |
27 | ///
28 | /// Gets or sets the AnalysisResult related to sexual content.
29 | ///
30 | [JsonPropertyName("sexualResult")]
31 | public AnalysisResult? SexualResult { get; set; }
32 |
33 | ///
34 | /// Gets or sets the AnalysisResult related to violence.
35 | ///
36 | [JsonPropertyName("violenceResult")]
37 | public AnalysisResult? ViolenceResult { get; set; }
38 | }
39 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/MaintenanceResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Response;
5 |
6 | ///
7 | /// Defines optional messaging for maintenance mode.
8 | ///
9 | public class MaintenanceResult
10 | {
11 | ///
12 | /// The maintenance notification title.
13 | ///
14 | ///
15 | /// Will utilize default if not defined.
16 | ///
17 | public string Title { get; set; } = string.Empty;
18 |
19 | ///
20 | /// The maintenance notification message.
21 | ///
22 | ///
23 | /// Will utilize default if not defined.
24 | ///
25 | public string Message { get; set; } = string.Empty;
26 |
27 | ///
28 | /// The maintenance notification note.
29 | ///
30 | ///
31 | /// Will utilize default if not defined.
32 | ///
33 | public string? Note { get; set; }
34 | }
35 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/ScoringResult.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public class ScoringResult
9 | {
10 | [JsonPropertyName("passed")]
11 | public bool Passed { get; set; } = false;
12 |
13 | [JsonPropertyName("custom_message")]
14 | public string CustomMessage { get; set; } = string.Empty;
15 | }
16 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/SemanticDependency.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Models.Response;
7 |
8 | public interface ISemanticDependency
9 | {
10 | ///
11 | /// Result of the dependency. This is the output that's injected into the prompt.
12 | ///
13 | [JsonPropertyName("result")]
14 | string Result { get; }
15 |
16 | ///
17 | /// Type of dependency, if any.
18 | ///
19 | [JsonPropertyName("type")]
20 | string? Type { get; }
21 | }
22 |
23 | ///
24 | /// Information about semantic dependencies of the prompt.
25 | ///
26 | public class SemanticDependency : ISemanticDependency
27 | {
28 | ///
29 | [JsonPropertyName("result")]
30 | public string Result { get; set; } = string.Empty;
31 |
32 | ///
33 | [JsonPropertyName("type")]
34 | public string Type { get; set; } = string.Empty;
35 |
36 | ///
37 | /// Context of the dependency. This can be either the prompt template or planner details.
38 | ///
39 | [JsonPropertyName("context")]
40 | public T? Context { get; set; } = default;
41 |
42 | public SemanticDependency(string result, T? context = default, string? type = null)
43 | {
44 | this.Result = result;
45 | this.Context = context;
46 | this.Type = type ?? typeof(T).Name;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Response/SpeechTokenResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Response;
5 |
6 | ///
7 | /// Token Response is a simple wrapper around the token and region
8 | ///
9 | public class SpeechTokenResponse
10 | {
11 | public string? Token { get; set; }
12 | public string? Region { get; set; }
13 | public bool? IsSuccess { get; set; }
14 | }
15 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Storage/ChatParticipant.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Text.Json.Serialization;
6 | using CopilotChat.WebApi.Storage;
7 |
8 | namespace CopilotChat.WebApi.Models.Storage;
9 |
10 | ///
11 | /// A chat participant is a user that is part of a chat.
12 | /// A user can be part of multiple chats, thus a user can have multiple chat participants.
13 | ///
14 | public class ChatParticipant : IStorageEntity
15 | {
16 | ///
17 | /// Participant ID that is persistent and unique.
18 | ///
19 | public string Id { get; set; }
20 |
21 | ///
22 | /// User ID that is persistent and unique.
23 | ///
24 | public string UserId { get; set; }
25 |
26 | ///
27 | /// Chat ID that this participant belongs to.
28 | ///
29 | public string ChatId { get; set; }
30 |
31 | ///
32 | /// The partition key for the source.
33 | ///
34 | [JsonIgnore]
35 | public string Partition => this.UserId;
36 |
37 | public ChatParticipant(string userId, string chatId)
38 | {
39 | this.Id = Guid.NewGuid().ToString();
40 | this.UserId = userId;
41 | this.ChatId = chatId;
42 | }
43 |
44 | public object Clone()
45 | {
46 | return new ChatParticipant(this.UserId, this.ChatId)
47 | {
48 | Id = this.Id,
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Storage/CtfdAuthApi.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Storage;
5 |
6 | public class CtfdAuthApi
7 | {
8 | public string Nonce { get; set; } = string.Empty;
9 | public string Cookie { get; set; } = string.Empty;
10 | }
11 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Models/Storage/MemoryTags.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Models.Storage;
5 |
6 | ///
7 | /// Tag names for kernel memory.
8 | ///
9 | internal static class MemoryTags
10 | {
11 | ///
12 | /// Associates memory with a specific chat
13 | ///
14 | public const string TagChatId = "chatid";
15 |
16 | ///
17 | /// Associates memory with specific type.
18 | ///
19 | public const string TagMemory = "memory";
20 | }
21 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/AzureSpeechOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Options;
5 |
6 | ///
7 | /// Configuration options for Azure speech recognition.
8 | ///
9 | public sealed class AzureSpeechOptions
10 | {
11 | public const string PropertyName = "AzureSpeech";
12 |
13 | ///
14 | /// Location of the Azure speech service to use (e.g. "South Central US")
15 | ///
16 | public string? Region { get; set; } = string.Empty;
17 |
18 | ///
19 | /// Key to access the Azure speech service.
20 | ///
21 | public string? Key { get; set; } = string.Empty;
22 | }
23 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/ChatArchiveSchemaInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.ComponentModel.DataAnnotations;
5 |
6 | namespace CopilotChat.WebApi.Options;
7 |
8 | ///
9 | /// Information on schema used to serialize chat archives.
10 | ///
11 | public record ChatArchiveSchemaInfo
12 | {
13 | ///
14 | /// The name of the schema.
15 | ///
16 | [Required, NotEmptyOrWhitespace]
17 | public string Name { get; init; } = "CopilotChat";
18 |
19 | ///
20 | /// The version of the schema.
21 | ///
22 | [Range(0, int.MaxValue)]
23 | public int Version { get; init; } = 1;
24 | }
25 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/ChatStoreOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Options;
5 |
6 | ///
7 | /// Configuration settings for the chat store.
8 | ///
9 | public class ChatStoreOptions
10 | {
11 | public const string PropertyName = "ChatStore";
12 |
13 | ///
14 | /// The type of chat store to use.
15 | ///
16 | public enum ChatStoreType
17 | {
18 | ///
19 | /// Non-persistent chat store
20 | ///
21 | Volatile,
22 |
23 | ///
24 | /// File-system based persistent chat store.
25 | ///
26 | Filesystem,
27 |
28 | ///
29 | /// Azure CosmosDB based persistent chat store.
30 | ///
31 | Cosmos
32 | }
33 |
34 | ///
35 | /// Gets or sets the type of chat store to use.
36 | ///
37 | public ChatStoreType Type { get; set; } = ChatStoreType.Volatile;
38 |
39 | ///
40 | /// Gets or sets the configuration for the file system chat store.
41 | ///
42 | [RequiredOnPropertyValue(nameof(Type), ChatStoreType.Filesystem)]
43 | public FileSystemOptions? Filesystem { get; set; }
44 |
45 | ///
46 | /// Gets or sets the configuration for the Azure CosmosDB chat store.
47 | ///
48 | [RequiredOnPropertyValue(nameof(Type), ChatStoreType.Cosmos)]
49 | public CosmosOptions? Cosmos { get; set; }
50 | }
51 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/ContentSafetyOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.ComponentModel.DataAnnotations;
6 |
7 | namespace CopilotChat.WebApi.Options;
8 |
9 | ///
10 | /// Configuration options for content safety.
11 | ///
12 | public class ContentSafetyOptions
13 | {
14 | public const string PropertyName = "ContentSafety";
15 |
16 | ///
17 | /// Whether to enable content safety.
18 | ///
19 | [Required]
20 | public bool Enabled { get; set; } = false;
21 |
22 | ///
23 | /// Azure Content Safety endpoints
24 | ///
25 | [RequiredOnPropertyValue(nameof(Enabled), true)]
26 | public string Endpoint { get; set; } = string.Empty;
27 |
28 | ///
29 | /// Key to access the content safety service.
30 | ///
31 | [RequiredOnPropertyValue(nameof(Enabled), true)]
32 | public string Key { get; set; } = string.Empty;
33 |
34 | ///
35 | /// Set the violation threshold. See https://learn.microsoft.com/en-us/azure/ai-services/content-safety/quickstart-image for details.
36 | ///
37 | [Range(0, 6)]
38 | public short ViolationThreshold { get; set; } = 4;
39 | }
40 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/FileSystemOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.ComponentModel.DataAnnotations;
5 |
6 | namespace CopilotChat.WebApi.Options;
7 |
8 | ///
9 | /// File system storage configuration.
10 | ///
11 | public class FileSystemOptions
12 | {
13 | ///
14 | /// Gets or sets the file path for persistent file system storage.
15 | ///
16 | [Required, NotEmptyOrWhitespace]
17 | public string FilePath { get; set; } = string.Empty;
18 | }
19 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/FrontendOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Options;
5 |
6 | ///
7 | /// Configuration options to be relayed to the frontend.
8 | ///
9 | public sealed class FrontendOptions
10 | {
11 | public const string PropertyName = "Frontend";
12 |
13 | ///
14 | /// Client ID for the frontend
15 | ///
16 | public string AadClientId { get; set; } = string.Empty;
17 | }
18 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/NotEmptyOrWhitespaceAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.ComponentModel.DataAnnotations;
6 |
7 | namespace CopilotChat.WebApi.Options;
8 |
9 | ///
10 | /// If the string is set, it must not be empty or whitespace.
11 | ///
12 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
13 | internal sealed class NotEmptyOrWhitespaceAttribute : ValidationAttribute
14 | {
15 | protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
16 | {
17 | if (value == null)
18 | {
19 | return ValidationResult.Success;
20 | }
21 |
22 | if (value is string s)
23 | {
24 | if (!string.IsNullOrWhiteSpace(s))
25 | {
26 | return ValidationResult.Success;
27 | }
28 |
29 | return new ValidationResult($"'{validationContext.MemberName}' cannot be empty or whitespace.");
30 | }
31 |
32 | return new ValidationResult($"'{validationContext.MemberName}' must be a string.");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/PluginOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 |
6 | namespace CopilotChat.WebApi.Options;
7 |
8 | ///
9 | /// Option for a single plugin.
10 | ///
11 | public class Plugin
12 | {
13 | ///
14 | /// The name of the plugin.
15 | ///
16 | public string Name { get; set; } = string.Empty;
17 |
18 | ///
19 | /// The url of the plugin.
20 | ///
21 | public Uri ManifestDomain { get; set; } = new Uri("http://localhost");
22 |
23 | ///
24 | /// The key of the plugin.
25 | ///
26 | public string Key { get; set; } = string.Empty;
27 | }
28 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/PrometheusTelemetryOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Options;
5 |
6 | public class PrometheusTelemetryOptions
7 | {
8 | public const string PropertyName = "PrometheusTelemetry";
9 |
10 | public string Endpoint { get; set; } = "http://localhost:4001";
11 | }
12 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Options/ServiceOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.ComponentModel.DataAnnotations;
5 |
6 | namespace CopilotChat.WebApi.Options;
7 |
8 | ///
9 | /// Configuration options for the CopilotChat service.
10 | ///
11 | public class ServiceOptions
12 | {
13 | public const string PropertyName = "Service";
14 |
15 | ///
16 | /// Timeout limit on requests to the service in seconds.
17 | ///
18 | [Range(0, int.MaxValue)]
19 | public double? TimeoutLimitInS { get; set; }
20 |
21 | ///
22 | /// Configuration Key Vault URI
23 | ///
24 | [Url]
25 | public string? KeyVault { get; set; }
26 |
27 | ///
28 | /// Local directory from which to load semantic plugins.
29 | ///
30 | public string? SemanticPluginsDirectory { get; set; }
31 |
32 | ///
33 | /// Local directory from which to load native plugins.
34 | ///
35 | public string? NativePluginsDirectory { get; set; }
36 |
37 | ///
38 | /// Setting indicating if the site is undergoing maintenance.
39 | ///
40 | public bool InMaintenance { get; set; }
41 | }
42 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/Chat/SemanticChatMemoryItem.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Plugins.Chat;
7 |
8 | ///
9 | /// A single entry in the chat memory.
10 | ///
11 | public class SemanticChatMemoryItem
12 | {
13 | ///
14 | /// Label for the chat memory item.
15 | ///
16 | [JsonPropertyName("label")]
17 | public string Label { get; set; }
18 |
19 | ///
20 | /// Details for the chat memory item.
21 | ///
22 | [JsonPropertyName("details")]
23 | public string Details { get; set; }
24 |
25 | ///
26 | /// Create a new chat memory item.
27 | ///
28 | /// Label of the item.
29 | /// Details of the item.
30 | public SemanticChatMemoryItem(string label, string details)
31 | {
32 | this.Label = label;
33 | this.Details = details;
34 | }
35 |
36 | ///
37 | /// Format the chat memory item as a string.
38 | ///
39 | /// A formatted string representing the item.
40 | public string ToFormattedString()
41 | {
42 | return $"{this.Label}: {this.Details?.Trim()}";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/OpenApi/GitHubPlugin/Model/Label.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Plugins.OpenApi.GitHubPlugin.Model;
7 |
8 | ///
9 | /// Represents a pull request label.
10 | ///
11 | public class Label
12 | {
13 | ///
14 | /// Gets or sets the ID of the label.
15 | ///
16 | [JsonPropertyName("id")]
17 | public long Id { get; set; }
18 |
19 | ///
20 | /// Gets or sets the name of the label.
21 | ///
22 | [JsonPropertyName("name")]
23 | public string Name { get; set; }
24 |
25 | ///
26 | /// Gets or sets the description of the label.
27 | ///
28 | [JsonPropertyName("description")]
29 | public string Description { get; set; }
30 |
31 | ///
32 | /// Initializes a new instance of the class.
33 | ///
34 | /// The ID of the label.
35 | /// The name of the label.
36 | /// The description of the label.
37 | public Label(long id, string name, string description)
38 | {
39 | this.Id = id;
40 | this.Name = name;
41 | this.Description = description;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/OpenApi/GitHubPlugin/Model/Repo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Plugins.OpenApi.GitHubPlugin.Model;
7 |
8 | ///
9 | /// Represents a GitHub Repo.
10 | ///
11 | public class Repo
12 | {
13 | ///
14 | /// Gets or sets the name of the repo
15 | ///
16 | [JsonPropertyName("name")]
17 | public string Name { get; set; }
18 |
19 | ///
20 | /// Gets or sets the full name of the repo
21 | ///
22 | [JsonPropertyName("full_name")]
23 | public string FullName { get; set; }
24 |
25 | ///
26 | /// Initializes a new instance of the .
27 | ///
28 | /// The name of the repository, e.g. "dotnet/runtime".
29 | /// The full name of the repository, e.g. "Microsoft/dotnet/runtime".
30 | public Repo(string name, string fullName)
31 | {
32 | this.Name = name;
33 | this.FullName = fullName;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/OpenApi/JiraPlugin/Model/CommentAuthor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Plugins.OpenApi.JiraPlugin.Model;
7 |
8 | ///
9 | /// Represents the Author of a comment.
10 | ///
11 | public class CommentAuthor
12 | {
13 | ///
14 | /// Gets or sets the Comment Author's display name.
15 | ///
16 | [JsonPropertyName("displayName")]
17 | public string DisplayName { get; set; }
18 |
19 | ///
20 | /// Initializes a new instance of the class.
21 | ///
22 | /// Name of Author
23 | public CommentAuthor(string displayName)
24 | {
25 | this.DisplayName = displayName;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/OpenApi/JiraPlugin/Model/CommentResponse.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Text.Json.Serialization;
6 |
7 | namespace CopilotChat.WebApi.Plugins.OpenApi.JiraPlugin.Model;
8 |
9 | ///
10 | /// Represents a the list of comments that make up a CommentResponse.
11 | ///
12 | public class CommentResponse
13 | {
14 | ///
15 | /// Gets or sets the list of all comments contained in this comment response.
16 | ///
17 | [JsonPropertyName("comments")]
18 | public IEnumerable AllComments { get; set; }
19 |
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | /// List of all comments on the Issue.
24 | public CommentResponse(IEnumerable allComments)
25 | {
26 | this.AllComments = allComments;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/OpenApi/JiraPlugin/Model/IndividualComments.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Text.Json.Serialization;
5 |
6 | namespace CopilotChat.WebApi.Plugins.OpenApi.JiraPlugin.Model;
7 |
8 | ///
9 | /// Represents an individual comment on an issue in jira.
10 | ///
11 | public class IndividualComments
12 | {
13 | ///
14 | /// Gets or sets the body of the comment.
15 | ///
16 | [JsonPropertyName("body")]
17 | public string Body { get; set; }
18 |
19 | ///
20 | /// Gets or sets the author name.
21 | ///
22 | [JsonPropertyName("author")]
23 | public CommentAuthor Author { get; set; }
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | /// The actual content of the comment.
29 | /// Author of the comment.
30 | public IndividualComments(string body, CommentAuthor author)
31 | {
32 | this.Body = body;
33 | this.Author = author;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Plugins/Utils/PromptUtils.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using static CopilotChat.WebApi.Models.Storage.CopilotChatMessage;
5 |
6 | namespace CopilotChat.WebApi.Plugins.Utils;
7 |
8 | ///
9 | /// Utility methods for prompt generation.
10 | ///
11 | public static class PromptUtils
12 | {
13 | ///
14 | /// Convert a chat message to a string in the format of: "Role: Content".
15 | ///
16 | /// The role of the author of the message.
17 | /// The content of the message.
18 | /// A formatted chat message string.
19 | internal static string? FormatChatHistoryMessage(AuthorRoles role, string content) => $"{role}: {content}";
20 | }
21 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/AppInsightsUserTelemetryInitializerService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using Microsoft.ApplicationInsights.Channel;
5 | using Microsoft.ApplicationInsights.DataContracts;
6 | using Microsoft.ApplicationInsights.Extensibility;
7 | using Microsoft.AspNetCore.Http;
8 |
9 | namespace CopilotChat.WebApi.Services;
10 |
11 | ///
12 | /// A telemetry initializer used by the TelemetryClient to fill in data for requests.
13 | /// This implementation injects the id of the current authenticated user (if there is one).
14 | ///
15 | public class AppInsightsUserTelemetryInitializerService : ITelemetryInitializer
16 | {
17 | public AppInsightsUserTelemetryInitializerService(IHttpContextAccessor httpContextAccessor)
18 | {
19 | this._contextAccessor = httpContextAccessor;
20 | }
21 |
22 | ///
23 | public void Initialize(ITelemetry telemetry)
24 | {
25 | if (telemetry is not RequestTelemetry requestTelemetry)
26 | {
27 | return;
28 | }
29 |
30 | var userId = AppInsightsTelemetryService.GetUserIdFromHttpContext(this._contextAccessor);
31 |
32 | telemetry.Context.User.Id = userId;
33 | }
34 |
35 | private readonly IHttpContextAccessor _contextAccessor;
36 | }
37 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/Ctfd/CtfdScorerMessageService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using CopilotChat.WebApi.Options;
5 | using Microsoft.Extensions.Options;
6 |
7 | namespace CopilotChat.WebApi.Services.Ctfd;
8 |
9 | public class CtfdScorerMessageService : ICtfdScorerMessageService
10 | {
11 | private readonly bool _flagSubmissionEnabled;
12 | private readonly string _flagValue;
13 |
14 | public CtfdScorerMessageService(IOptions challengeOptions)
15 | {
16 | this._flagSubmissionEnabled = false;
17 | this._flagValue = "";
18 |
19 | if (challengeOptions.Value.Ctfd != null)
20 | {
21 | this._flagSubmissionEnabled = true;
22 | this._flagValue = challengeOptions.Value.Ctfd.Flag;
23 | }
24 | }
25 |
26 | public string GetScorerMessage()
27 | {
28 | if (!this._flagSubmissionEnabled)
29 | {
30 | return string.Empty;
31 | }
32 |
33 | return $"\n\nHere's the flag for this challlenge that was already submitted on your behalf: \"{this._flagValue}\".";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/Ctfd/ICtfdFlagSubmissionService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Threading.Tasks;
5 | using CopilotChat.WebApi.Models.Storage;
6 |
7 | namespace CopilotChat.WebApi.Services.Ctfd;
8 |
9 | public interface ICtfdFlagSubmissionService
10 | {
11 | CtfdAuthApi? GetCtfdAuth();
12 | Task SubmitFlagAsync(string chatId);
13 | Task SubmitFlagAsync(string chatId, CtfdAuthApi ctfdAuth);
14 | }
15 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/Ctfd/ICtfdScorerMessageService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services.Ctfd;
5 |
6 | public interface ICtfdScorerMessageService
7 | {
8 | public string GetScorerMessage();
9 | }
10 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/Ctfd/IItsDangerousSignerService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services.Ctfd;
5 |
6 | public interface IItsDangerousSignerService
7 | {
8 | public string Sign(string value);
9 | }
10 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/IContentSafetyService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using CopilotChat.WebApi.Models.Response;
9 | using Microsoft.AspNetCore.Http;
10 |
11 | namespace CopilotChat.WebApi.Services;
12 |
13 | ///
14 | /// Defines a service that performs content safety analysis on images.
15 | ///
16 | public interface IContentSafetyService : IDisposable
17 | {
18 | ///
19 | /// Invokes a sync API to perform harmful content analysis on image.
20 | ///
21 | /// Image content file
22 | /// A token to cancel the operation.
23 | /// A task that represents the asynchronous operation. The task result contains the image analysis response.
24 | Task ImageAnalysisAsync(IFormFile formFile, CancellationToken cancellationToken);
25 |
26 | ///
27 | /// Parse the analysis result and return the violated categories.
28 | ///
29 | /// The content analysis result.
30 | /// Optional violation threshold.
31 | /// The list of violated category names. Will return an empty list if there is no violation.
32 | List ParseViolatedCategories(ImageAnalysisResponse imageAnalysisResponse, short threshold);
33 | }
34 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/IMaintenanceAction.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace CopilotChat.WebApi.Services;
8 |
9 | ///
10 | /// Defines discrete maintenance action responsible for both inspecting state
11 | /// and performing maintenance.
12 | ///
13 | public interface IMaintenanceAction
14 | {
15 | ///
16 | /// Calling site to initiate maintenance action.
17 | ///
18 | /// true if maintenance needed or in progress
19 | Task InvokeAsync(CancellationToken cancellation = default);
20 | }
21 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/IMetapromptSanitizationService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using CopilotChat.WebApi.Models.Response;
5 | using CopilotChat.WebApi.Models.Storage;
6 |
7 | namespace CopilotChat.WebApi.Services;
8 |
9 | public interface IMetapromptSanitizationService
10 | {
11 | ///
12 | /// Sanitize the chat session to remove metaprompt information.
13 | ///
14 | ///
15 | ///
16 | public ChatSession ChatSession(ChatSession chatSession);
17 |
18 | ///
19 | /// Sanitize the bot response prompt to remove metaprompt information.
20 | ///
21 | ///
22 | ///
23 | ///
24 | ///
25 | ///
26 | ///
27 | ///
28 | ///
29 | public BotResponsePrompt BotResponsePrompt(BotResponsePrompt prompt);
30 |
31 | ///
32 | /// Sanitize the copilot chat message to remove metaprompt information.
33 | ///
34 | ///
35 | ///
36 | public CopilotChatMessage CopilotChatMessage(CopilotChatMessage copilotChatMessage);
37 | }
38 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/IPrometheusTelemetryService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services;
5 |
6 | public interface IPrometheusTelemetryService
7 | {
8 | ///
9 | /// Records a metric with a given value.
10 | ///
11 | ///
12 | ///
13 | public void RecordMetric(string metricName, double value);
14 | }
15 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/IRagService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services;
5 |
6 | public interface IRagService
7 | {
8 | bool IsRagEnabled();
9 | string GetDocument(string? ragDocument, string? ragUserInput);
10 | }
11 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/ISessionMetricService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services;
5 |
6 | public interface ISessionMetricService
7 | {
8 | public void OnConnected(string connectionId);
9 | public void OnDisconnect(string connectionId);
10 |
11 | public void TrackUserId(string userId);
12 | }
13 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/ITelemetryService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | namespace CopilotChat.WebApi.Services;
5 |
6 | ///
7 | /// Interface for common telemetry events to track actions across the semantic kernel.
8 | ///
9 | public interface ITelemetryService
10 | {
11 | ///
12 | /// Creates a telemetry event when a function is executed.
13 | ///
14 | /// Name of the plugin
15 | /// Function name
16 | /// If the function executed successfully
17 | void TrackPluginFunction(string pluginName, string functionName, bool success);
18 | }
19 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/MemoryMigration/ChatMigrationStatus.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 | namespace CopilotChat.WebApi.Services.MemoryMigration;
4 |
5 | ///
6 | /// Set of migration states/status for chat memory migration.
7 | ///
8 | ///
9 | /// Interlocked.CompareExchange doesn't work with enums.
10 | ///
11 | public sealed class ChatMigrationStatus
12 | {
13 | ///
14 | /// Represents state where no migration is required or in progress.
15 | ///
16 | public static ChatMigrationStatus None { get; } = new ChatMigrationStatus(nameof(None));
17 |
18 | ///
19 | /// Represents state where no migration is required.
20 | ///
21 | public static ChatMigrationStatus RequiresUpgrade { get; } = new ChatMigrationStatus(nameof(RequiresUpgrade));
22 |
23 | ///
24 | /// Represents state where no migration is in progress.
25 | ///
26 | public static ChatMigrationStatus Upgrading { get; } = new ChatMigrationStatus(nameof(Upgrading));
27 |
28 | ///
29 | /// The state label (no functional impact, but helps debugging).
30 | ///
31 | public string Label { get; }
32 |
33 | private ChatMigrationStatus(string label)
34 | {
35 | this.Label = label;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/MemoryMigration/IChatMemoryMigrationService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace CopilotChat.WebApi.Services.MemoryMigration;
8 |
9 | ///
10 | /// Defines contract for migrating chat memory.
11 | ///
12 | public interface IChatMemoryMigrationService
13 | {
14 | ///
15 | /// Migrates all non-document memory to the kernel memory index.
16 | /// Subsequent/redunant migration is non-destructive/no-impact to migrated index.
17 | ///
18 | Task MigrateAsync(CancellationToken cancellationToken = default);
19 | }
20 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/MemoryMigration/IChatMigrationMonitor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace CopilotChat.WebApi.Services.MemoryMigration;
8 |
9 | ///
10 | /// Contract for monitoring the status of chat memory migration.
11 | ///
12 | public interface IChatMigrationMonitor
13 | {
14 | ///
15 | /// Inspects the current state of affairs to determine the chat migration status.
16 | ///
17 | Task GetCurrentStatusAsync(CancellationToken cancellationToken = default);
18 | }
19 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Services/RagService.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 | using CopilotChat.WebApi.Options;
6 | using Microsoft.Extensions.Options;
7 |
8 | namespace CopilotChat.WebApi.Services;
9 |
10 | public class RagService : IRagService
11 | {
12 | private readonly ChallengeOptions.RagInputOptions? _ragOptions;
13 |
14 | public RagService(IOptions options)
15 | {
16 | this._ragOptions = options.Value.RagInput;
17 | }
18 |
19 | public bool IsRagEnabled()
20 | {
21 | return this._ragOptions != null;
22 | }
23 |
24 | public string GetDocument(string? ragDocument, string? ragUserInput)
25 | {
26 | if (this._ragOptions != null)
27 | {
28 | if (this._ragOptions.IsReadOnly)
29 | {
30 | var document = this._ragOptions.DefaultDocument;
31 | if (string.IsNullOrEmpty(this._ragOptions.DocumentTemplate))
32 | {
33 | document += "\n" + (ragUserInput ?? "");
34 | }
35 | else
36 | {
37 | document = document.Replace(this._ragOptions.DocumentTemplate, ragUserInput ?? "", StringComparison.InvariantCultureIgnoreCase);
38 | }
39 | return document;
40 | }
41 |
42 | return ragDocument ?? this._ragOptions.DefaultDocument;
43 | }
44 | return "";
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Storage/ChatSessionRepository.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using CopilotChat.WebApi.Models.Storage;
8 | using Microsoft.Extensions.Caching.Memory;
9 |
10 | namespace CopilotChat.WebApi.Storage;
11 |
12 | ///
13 | /// A repository for chat sessions.
14 | ///
15 | public class ChatSessionRepository : Repository
16 | {
17 | ///
18 | /// Initializes a new instance of the ChatSessionRepository class.
19 | ///
20 | /// The storage context.
21 | /// The memory cache.
22 | public ChatSessionRepository(IStorageContext storageContext, IMemoryCache memoryCache)
23 | : base(storageContext, memoryCache)
24 | {
25 | }
26 |
27 | ///
28 | /// Retrieves all chat sessions.
29 | ///
30 | /// A list of ChatMessages.
31 | public async Task> GetAllChatsAsync()
32 | {
33 | var chats = await base.StorageContext.QueryEntitiesAsync(e => true);
34 | return chats.Where(x => x.IsDeleted = false);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Storage/IStorageEntity.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using System;
5 |
6 | namespace CopilotChat.WebApi.Storage;
7 |
8 | public interface IStorageEntity : ICloneable
9 | {
10 | ///
11 | /// Unique ID of the entity.
12 | ///
13 | string Id { get; set; }
14 |
15 | ///
16 | /// Partition key value.
17 | ///
18 | string Partition { get; }
19 | }
20 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/Utilities/AskConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | using CopilotChat.WebApi.Auth;
5 | using CopilotChat.WebApi.Models.Request;
6 | using Microsoft.SemanticKernel.Orchestration;
7 |
8 | namespace CopilotChat.WebApi.Utilities;
9 |
10 | ///
11 | /// Converts variables to , inserting some system variables along the way.
12 | ///
13 | public class AskConverter
14 | {
15 | private readonly IAuthInfo _authInfo;
16 |
17 | public AskConverter(IAuthInfo authInfo)
18 | {
19 | this._authInfo = authInfo;
20 | }
21 |
22 | ///
23 | /// Converts variables to , inserting some system variables along the way.
24 | ///
25 | public ContextVariables GetContextVariables(Ask ask)
26 | {
27 | const string userIdKey = "userId";
28 | const string userNameKey = "userName";
29 | var contextVariables = new ContextVariables(ask.Input);
30 | foreach (var variable in ask.Variables)
31 | {
32 | if (variable.Key != userIdKey && variable.Key != userNameKey)
33 | {
34 | contextVariables.Set(variable.Key, variable.Value);
35 | }
36 | }
37 |
38 | contextVariables.Set(userIdKey, this._authInfo.UserId);
39 | contextVariables.Set(userNameKey, this._authInfo.Name);
40 | return contextVariables;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapi/data/README.md:
--------------------------------------------------------------------------------
1 | # Tesseract OCR Support
2 |
3 | This API supports the ability to upload image file formats such as png, jpg and tiff via the [Tesseract](https://www.nuget.org/packages/Tesseract) nuget package.
4 | You will need to obtain one or more [tessdata language data files](https://github.com/tesseract-ocr/tessdata) such as `eng.traineddata` and add them to your `./data` directory or the location specified in the `Tesseract.FilePath` location in `./appsettings.json`.
5 |
6 | If you do not add any `.traineddata` files, you will receive a runtime exception when attempting to upload one of these image formats.
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/.env.example:
--------------------------------------------------------------------------------
1 | # Required Variables
2 | REACT_APP_BACKEND_URI=https://localhost:40443/
3 |
4 | # To enable HTTPS, uncomment the following variables
5 | # HTTPS="true"
6 | # Replace with your locally-trusted cert file
7 | # SSL_CRT_FILE=local-cert.crt
8 | # Replace with your locally-trusted cert key
9 | # SSL_KEY_FILE=local-cert.key
10 |
11 | # For CI and testing purposes only
12 | REACT_APP_TEST_USER_ACCOUNT1=
13 | REACT_APP_TEST_USER_PASSWORD1=
14 | REACT_APP_TEST_USER_ACCOUNT2=
15 | REACT_APP_TEST_USER_PASSWORD2=
16 |
17 | REACT_APP_TEST_JIRA_EMAIL=
18 | REACT_APP_TEST_JIRA_ACCESS_TOKEN=
19 | REACT_APP_TEST_JIRA_SERVER_URL=
20 |
21 | REACT_APP_TEST_GITHUB_ACCESS_TOKEN=
22 | REACT_APP_TEST_GITHUB_ACCOUNT_OWNER=
23 | REACT_APP_TEST_GITHUB_REPOSITORY_NAME=
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/.prettierrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | bracketSpacing: true,
3 | printWidth: 120,
4 | singleQuote: true,
5 | tabWidth: 4,
6 | trailingComma: 'all',
7 | useTabs: false,
8 | };
9 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "msedge",
9 | "request": "launch",
10 | "name": "Launch Edge against localhost",
11 | "url": "http://localhost:3000",
12 | "webRoot": "${workspaceFolder}"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Loading...
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-1.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-2.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-3.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-4.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/bot-icons/bot-icon-5.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/custom.d.ts:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | declare module '*.svg' {
5 | import * as React from 'react';
6 |
7 | export const ReactComponent: React.FunctionComponent & { title?: string }>;
8 |
9 | const src: string;
10 | export default src;
11 | }
12 | declare module '*.png' {
13 | import * as React from 'react';
14 |
15 | export const ReactComponent: React.FunctionComponent & { title?: string }>;
16 |
17 | const src: string;
18 | export default src;
19 | }
20 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/plugin-icons/add-plugin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/plugin-icons/add-plugin.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/plugin-icons/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/plugin-icons/github.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/plugin-icons/jira.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/plugin-icons/jira.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/plugin-icons/ms-graph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/AI-Red-Teaming-Playground-Labs/bf41be62f4a86abe504c6eaea1a13d7322b58884/src/chat-copilot/webapp/src/assets/plugin-icons/ms-graph.png
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/assets/strings.ts:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | export const COPY = {
5 | STEPWISE_RESULT_NOT_FOUND_REGEX: /(Result not found, review _stepsTaken to see what happened\.)\s+(\[{.*}])/g,
6 | CHAT_DELETED_MESSAGE: (chatName?: string) =>
7 | `Chat ${
8 | chatName ? `{${chatName}} ` : ''
9 | }has been removed by another user. You can still access the latest chat history for now. All chat content will be cleared once you refresh or exit the application.`,
10 | REFRESH_APP_ADVISORY: 'Please refresh the page to ensure you have the latest data.',
11 | };
12 |
--------------------------------------------------------------------------------
/src/chat-copilot/webapp/src/components/chat/chat-history/ChatHistory.tsx:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation.
2 | // Licensed under the MIT License.
3 |
4 | import { makeStyles, shorthands, tokens } from '@fluentui/react-components';
5 | import React from 'react';
6 | import { IChatMessage } from '../../../libs/models/ChatMessage';
7 | import { ChatHistoryItem } from './ChatHistoryItem';
8 |
9 | const useClasses = makeStyles({
10 | root: {
11 | ...shorthands.gap(tokens.spacingVerticalM),
12 | display: 'flex',
13 | flexDirection: 'column',
14 | maxWidth: '900px',
15 | width: '100%',
16 | justifySelf: 'center',
17 | },
18 | item: {
19 | display: 'flex',
20 | flexDirection: 'column',
21 | },
22 | });
23 |
24 | interface ChatHistoryProps {
25 | messages: IChatMessage[];
26 | }
27 |
28 | export const ChatHistory: React.FC = ({ messages }) => {
29 | const classes = useClasses();
30 |
31 | return (
32 |
21 |
22 | {
23 | 'Please ensure your ".env" file is set up correctly with all environment variables defined in ".env.example" then restart the app.'
24 | }
25 |
26 | You are missing the following variables: {missingVariables.join(', ')}
27 |