Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Copilot Studio Client API and SPA Sample #59

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

svandenhoven
Copy link

@svandenhoven svandenhoven commented Jan 20, 2025

Description

The Copilot Studio Client API and SPA Sample is an example application that demonstrates how a user can log in with their Entra ID account on a Single Page Application (SPA) built with React. This application utilizes a .NET API that leverages the Microsoft 365 Agents SDK. Through this setup, the API can interact with any Copilot Studio Agent, enabling the creation of conversations that can be accessed via a React SPA.

Architecture

graph TD

    A[React SPA] -->|1 Login| F[Entra ID]
    F -->|2 Access Token| A
    A -->|3 API Request with Access Token| B[Custom API]
    B -->|4 Request Access Token on behalf of user| F
    F -->|5 Access Token| B
    B -->|6 API Request with Access Token| C[CopilotStudio API]
    C -->|13 API Response| B
    B -->|14 API Response| A
    C -->|7 Call Agent| G[Copilot Agent]
    G -->|12 Agent Response| C

    G -.->|8 Query| D[Search Index]
    D -.->|9 Response| G
    G -.->|10 Query| E[OpenAI]
    E -.->|11 Response| G

    subgraph Optional Components
        direction TB
        D[Search Index]
        E[OpenAI]
    end
Loading

To Test

See in the README.md in folder "copilot_studio_client_api_and_spa" how to configure the sample to test it.

Changes

This pull request introduces a new sample API project, CopilotStudioClientSampleAPI, which integrates with Microsoft Copilot Studio. The changes include adding new package dependencies, updating the solution file, and implementing the API's functionality.

New Sample API Project:

  • Project Setup and Dependencies:

    • Added new package dependencies in Directory.Packages.props for Microsoft.AspNetCore.Authentication.OpenIdConnect, Microsoft.Identity.Web, Microsoft.Identity.Web.DownstreamApi, and Swashbuckle.AspNetCore.
    • Created a new project file CopilotStudioClientSampleAPI.csproj with references to necessary packages and project dependencies.
    • Added dotnet-tools.json to manage .NET tools for the project.
  • Solution Configuration:

    • Updated Microsoft.Agents.SDK.sln to include the new CopilotStudioClientSampleAPI project. [1] [2] [3]
  • API Implementation:

    • Implemented the Chat controller in Controllers/Chat.cs to handle chat interactions with Copilot Studio.
    • Added model classes Conversation, ChatResponse, MessageRequest, and Content in Models/ChatResponse.cs to structure API responses and requests.
    • Configured the API in Program.cs to set up services, authentication, and CORS policy.
  • Documentation and Configuration:

    • Added a README.md file outlining the project architecture, setup instructions, and configuration details.
    • Included an HTTP request sample file CopilotStudioClientSampleAPI.http for testing the API endpoints.

@svandenhoven svandenhoven requested a review from a team as a code owner January 20, 2025 13:31
@github-actions github-actions bot added ML: Samples Tags changes to samples From Fork This PR was created from a Fork labels Jan 20, 2025
@svandenhoven svandenhoven changed the title Added Copilot Studio CL Adding Copilot Studio Client API and SPA Sample Jan 20, 2025
@@ -16,6 +16,10 @@
<Microsoft_AspNetCore_PkgVer>8.0.11</Microsoft_AspNetCore_PkgVer>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.11" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the Microsoft_AspNetCore_PkgVer variable for the version of Asp.net

/// <summary>
/// Connection Settings extension for the sample to include appID and TeantId for creating authentication token.
/// </summary>
internal class SampleConnectionSettings : ConnectionSettings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you included this?
if your doing token exchange within a given tenant you do not need this you can use the base settings and drop Tenant ID and Application ID, using the tenant and application id of the host site for the OBO exchange.

@@ -0,0 +1,13 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any build changes, any reason this is here? it will not get restored during build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
From Fork This PR was created from a Fork ML: Samples Tags changes to samples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants