// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Json.Schema;
using Json.Schema.Generation;
using Microsoft.Teams.AI.Annotations;
using Microsoft.Teams.AI.Messages;
using Microsoft.Teams.Common.Extensions;
using Microsoft.Teams.Common.Json;
namespace Microsoft.Teams.AI;
///
/// defines a block of code that
/// can be called by a model
///
[JsonConverter(typeof(TrueTypeJsonConverter))]
[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
public interface IFunction
{
///
/// the unique name
///
public string Name { get; }
///
/// a description of what the function
/// should be used for
///
public string? Description { get; }
///
/// the Json Schema representing what
/// parameters the function accepts
///
public JsonSchema? Parameters { get; }
}
///
/// defines a block of code that
/// can be called by a model
///
[Obsolete("Microsoft.Teams.AI is deprecated and will be removed by end of summer 2026.")]
public class Function : IFunction
{
[JsonPropertyName("name")]
[JsonPropertyOrder(0)]
public string Name { get; set; }
[JsonPropertyName("description")]
[JsonPropertyOrder(1)]
public string? Description { get; set; }
[JsonPropertyName("parameters")]
[JsonPropertyOrder(2)]
public JsonSchema? Parameters { get; set; }
[JsonIgnore]
public Delegate Handler { get; set; }
public Function(string name, string? description, Delegate handler)
{
Name = name;
Description = description;
Handler = handler;
Parameters = GenerateParametersSchema(handler);
}
public Function(string name, string? description, JsonSchema parameters, Delegate handler)
{
Name = name;
Description = description;
Parameters = parameters;
Handler = handler;
}
internal Task