// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI;
///
/// Contains extension methods for the class.
///
public static class ChatMessageStoreExtensions
{
///
/// Adds message filtering to an existing store, so that messages passed to the store and messages produced by the store
/// can be filtered, updated or replaced.
///
/// The store to add the message filter to.
/// An optional filter function to apply to messages produced by the store. If null, no filter is applied at this
/// stage.
/// An optional filter function to apply to the invoked context messages before they are passed to the store. If null, no
/// filter is applied at this stage.
/// The with filtering applied.
public static ChatMessageStore WithMessageFilters(
this ChatMessageStore store,
Func, IEnumerable>? invokingMessagesFilter = null,
Func? invokedMessagesFilter = null)
{
return new ChatMessageStoreMessageFilter(
innerChatMessageStore: store,
invokingMessagesFilter: invokingMessagesFilter,
invokedMessagesFilter: invokedMessagesFilter);
}
///
/// Decorates the provided chat message store so that it does not store messages produced by any .
///
/// The store to add the message filter to.
/// A new instance that filters out messages so they do not get stored.
public static ChatMessageStore WithAIContextProviderMessageRemoval(this ChatMessageStore store)
{
return new ChatMessageStoreMessageFilter(
innerChatMessageStore: store,
invokedMessagesFilter: (ctx) =>
{
ctx.AIContextProviderMessages = null;
return ctx;
});
}
}