Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Purview/IPurviewClient.cs
eoindoherty1 b19860b8a8 .NET: Implement Purview middleware in dotnet (#1949)
* Move Purview integration logic into middleware

* Improve error handling and user id management

* Rename purview package

* Handle 402s more explicitly; add Middleware generation methods; don't ignore exceptions

* Use DI container; pass scope id to PC

* Add protection scope caching

* Wrap more exceptions in PurviewClient

* Remove block check dedup; add tests

* Refactor PurviewWrapper intialization; Add unit tests

* Use different .Use method and add IDisposable stub

* Add background job processing for Purview

* Misc comment cleanup

* Apply copilot comments

* Fix formatting

* Formatting other files to fix pipeline

* Small updates to settings and exceptions

* Add README

* Move Purview sample

* Address review comments and update XML comments

* Newline after namespace

* Move public Purview classes to single namespace; Clean up csproj and slnx

* Commit the renames

* Remove unused openAI dependency

---------

Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
2025-11-14 00:50:08 +00:00

57 lines
3.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Agents.AI.Purview.Models.Common;
using Microsoft.Agents.AI.Purview.Models.Requests;
using Microsoft.Agents.AI.Purview.Models.Responses;
namespace Microsoft.Agents.AI.Purview;
/// <summary>
/// Defines methods for interacting with the Purview service, including content processing,
/// protection scope management, and activity tracking.
/// </summary>
/// <remarks>This interface provides methods to interact with various Purview APIs. It includes processing content, managing protection
/// scopes, and sending content activity data. Implementations of this interface are expected to handle communication
/// with the Purview service and manage any necessary authentication or error handling.</remarks>
internal interface IPurviewClient
{
/// <summary>
/// Get user info from auth token.
/// </summary>
/// <param name="cancellationToken">The cancellation token used to cancel async processing.</param>
/// <param name="tenantId">The default tenant id used to retrieve the token and its info.</param>
/// <returns>The token info from the token.</returns>
/// <exception cref="InvalidOperationException">Throw if the token was invalid or could not be retrieved.</exception>
Task<TokenInfo> GetUserInfoFromTokenAsync(CancellationToken cancellationToken, string? tenantId = default);
/// <summary>
/// Call ProcessContent API.
/// </summary>
/// <param name="request">The request containing the content to process.</param>
/// <param name="cancellationToken">The cancellation token used to cancel async processing.</param>
/// <returns>The response from the Purview API.</returns>
/// <exception cref="PurviewException">Thrown for validation, auth, and network errors.</exception>
Task<ProcessContentResponse> ProcessContentAsync(ProcessContentRequest request, CancellationToken cancellationToken);
/// <summary>
/// Call user ProtectionScope API.
/// </summary>
/// <param name="request">The request containing the protection scopes metadata.</param>
/// <param name="cancellationToken">The cancellation token used to cancel async processing.</param>
/// <returns>The protection scopes that apply to the data sent in the request.</returns>
/// <exception cref="PurviewException">Thrown for validation, auth, and network errors.</exception>
Task<ProtectionScopesResponse> GetProtectionScopesAsync(ProtectionScopesRequest request, CancellationToken cancellationToken);
/// <summary>
/// Call contentActivities API.
/// </summary>
/// <param name="request">The request containing the content metadata. Used to generate interaction records.</param>
/// <param name="cancellationToken">The cancellation token used to cancel async processing.</param>
/// <returns>The response from the Purview API.</returns>
/// <exception cref="PurviewException">Thrown for validation, auth, and network errors.</exception>
Task<ContentActivitiesResponse> SendContentActivitiesAsync(ContentActivitiesRequest request, CancellationToken cancellationToken);
}