// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using System.Linq;
using Azure.AI.Agents.Persistent;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Bot.ObjectModel;
///
/// Extension methods for .
///
internal static class FileSearchToolExtensions
{
///
/// Creates a from a .
///
/// Instance of
internal static FileSearchToolDefinition CreateFileSearchToolDefinition(this FileSearchTool tool)
{
Throw.IfNull(tool);
// TODO: Add support for FileSearchToolDefinitionDetails.
return new FileSearchToolDefinition();
}
///
/// Creates an from a .
///
/// Instance of
/// A new instance configured with the vector store IDs.
internal static OpenAI.Responses.FileSearchTool CreateFileSearchTool(this FileSearchTool tool)
{
Throw.IfNull(tool);
return new OpenAI.Responses.FileSearchTool(tool.GetVectorStoreIds());
}
///
/// Get the vector store IDs for the specified .
///
/// Instance of
internal static List? GetVectorStoreIds(this FileSearchTool tool)
{
return tool.VectorStoreIds?.LiteralValue.ToList();
}
internal static IList? GetVectorStoreConfigurations(this FileSearchTool tool)
{
var dataSources = tool.ExtensionData?.GetPropertyOrNull(InitializablePropertyPath.Create("options.configurations"));
return dataSources?.Values.Select(value => value.CreateVectorStoreConfiguration()).ToList();
}
internal static VectorStoreConfigurations CreateVectorStoreConfiguration(this RecordDataValue value)
{
Throw.IfNull(value);
var storeName = value.GetPropertyOrNull(InitializablePropertyPath.Create("storeName"))?.Value;
Throw.IfNullOrEmpty(storeName);
var dataSources = value.GetDataSources();
Throw.IfNull(dataSources);
return new VectorStoreConfigurations(storeName, new VectorStoreConfiguration(dataSources));
}
}