// Copyright (c) Microsoft. All rights reserved. using Microsoft.Agents.AI.DurableTask; using Microsoft.Azure.Functions.Worker.Core.FunctionMetadata; namespace Microsoft.Agents.AI.Hosting.AzureFunctions; /// /// Provides factory methods for creating common instances /// used by function metadata transformers. /// internal static class FunctionMetadataFactory { /// /// Creates function metadata for an entity trigger function. /// /// The base name used to derive the entity function name. /// A configured for an entity trigger. internal static DefaultFunctionMetadata CreateEntityTrigger(string name) { return new DefaultFunctionMetadata() { Name = AgentSessionId.ToEntityName(name), Language = "dotnet-isolated", RawBindings = [ """{"name":"encodedEntityRequest","type":"entityTrigger","direction":"In"}""", """{"name":"client","type":"durableClient","direction":"In"}""" ], EntryPoint = BuiltInFunctions.RunAgentEntityFunctionEntryPoint, ScriptFile = BuiltInFunctions.ScriptFile, }; } /// /// Creates function metadata for an HTTP trigger function. /// /// The base name used to derive the HTTP function name. /// The HTTP route for the trigger. /// The entry point method for the HTTP trigger. /// The allowed HTTP methods as a JSON array fragment (e.g., "\"get\""). Defaults to POST. /// A configured for an HTTP trigger. internal static DefaultFunctionMetadata CreateHttpTrigger(string name, string route, string entryPoint, string methods = "\"post\"") { return new DefaultFunctionMetadata() { Name = $"{BuiltInFunctions.HttpPrefix}{name}", Language = "dotnet-isolated", RawBindings = [ $"{{\"name\":\"req\",\"type\":\"httpTrigger\",\"direction\":\"In\",\"authLevel\":\"function\",\"methods\": [{methods}],\"route\":\"{route}\"}}", "{\"name\":\"$return\",\"type\":\"http\",\"direction\":\"Out\"}", "{\"name\":\"client\",\"type\":\"durableClient\",\"direction\":\"In\"}" ], EntryPoint = entryPoint, ScriptFile = BuiltInFunctions.ScriptFile, }; } /// /// Creates function metadata for an activity trigger function. /// /// The name of the activity function. /// A configured for an activity trigger. internal static DefaultFunctionMetadata CreateActivityTrigger(string functionName) { return new DefaultFunctionMetadata() { Name = functionName, Language = "dotnet-isolated", RawBindings = [ """{"name":"input","type":"activityTrigger","direction":"In","dataType":"String"}""", """{"name":"durableTaskClient","type":"durableClient","direction":"In"}""" ], EntryPoint = BuiltInFunctions.InvokeWorkflowActivityFunctionEntryPoint, ScriptFile = BuiltInFunctions.ScriptFile, }; } /// /// Creates function metadata for an orchestration trigger function. /// /// The name of the orchestration function. /// The entry point method for the orchestration trigger. /// A configured for an orchestration trigger. internal static DefaultFunctionMetadata CreateOrchestrationTrigger(string functionName, string entryPoint) { return new DefaultFunctionMetadata() { Name = functionName, Language = "dotnet-isolated", RawBindings = [ """{"name":"context","type":"orchestrationTrigger","direction":"In"}""" ], EntryPoint = entryPoint, ScriptFile = BuiltInFunctions.ScriptFile, }; } }