Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple native function arguments of many types #1195

Merged
merged 9 commits into from
Jun 16, 2023

Commits on Jun 13, 2023

  1. Add native function support for multiple arguments, non-string args, …

    …and non-string returns
    
    - Native skills can now have any number of parameters. The parameters are populated from context variables of the same name.  If no context variable exists for that name, it'll be populated with a default value if one was supplied via either an attribute or a default parameter value, or if there is none, the function will fail to be invoked. The first parameter may also be populated from "input" if it fails to get input by its name or default value.
    - Descriptions are now specified with the .NET DescriptionAttribute, and DefaultValue with the DefaultValueAttribute.  The C# compiler is aware of the DefaultValueAttribute and ensures the type of the value provided matches that of the type of the parameter.  Default values can now also be specified using optional parameter values.
    - SKFunction is now purely a marker attribute, other than for sensitivity. It's sole purpose is to subset which public members are imported as native functions when a skill is imported. It was already the case that the attribute wasn't needed when importing a function directly from a delegate; that requirement has also been lifted when importing from a MethodInfo.
    - SKFunctionContextParameterAttribute has been obsoleted and will be removed subsequently.  DescriptionAttribute, DefaultValueAttribute, and SKName attribute are used instead.  In rare situations where the method needs access to a variable that's not defined in its signature, it can use the SKParameter attribute on the method, which does have Description and DefaultValue optional properties.
    - SKFunctionInputAttribute has been obsoleted and will be removed subsequently.  DescriptionAttribute, DefaultValueAttribute, and SKName attribute are used instead (the latter with "Input" as the name). However, the need to use SKName should be exceedingly rare.
    - InvokeAsync will now catch exceptions and store the exception into the context.  This means native skills should handle all failures by throwing exceptions rather than by directly interacting with the context.
    - Updated name selection heuristic to strip off an "Async" suffix for async methods.  There are now very few reasons to use [SKName] on a method.
    - Added support for ValueTasks as return types, just for completeness so that developers don't need to think about it. It just works.
    - Added ability to accept an ILogger or CancellationToken into a method; they're populated from the SKContext.  With that, there are very few reasons left to pass an SKContext into a native function.
    - Added support for non-string arguments. All C# primitive types and many core .NET types are supported, with their corresponding TypeConverters used to parse the string context variable into the appropriate type. Custom types attributed with TypeConverterAttribute may also be used, and the associated TypeConverter will be used as is appropriate.  It's the same mechanism used by UI frameworks like WinForms as well as ASP.NET MVC.
    - Similarly, added support for non-string return types.
    stephentoub committed Jun 13, 2023
    Configuration menu
    Copy the full SHA
    009ccc9 View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2023

  1. Configuration menu
    Copy the full SHA
    1c010fd View commit details
    Browse the repository at this point in the history

Commits on Jun 15, 2023

  1. Configuration menu
    Copy the full SHA
    d8bf63f View commit details
    Browse the repository at this point in the history

Commits on Jun 16, 2023

  1. Configuration menu
    Copy the full SHA
    9ad839c View commit details
    Browse the repository at this point in the history
  2. Fix breaks after merge

    name committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    78f154c View commit details
    Browse the repository at this point in the history
  3. Increase package minor version

    name committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    4ccf8e6 View commit details
    Browse the repository at this point in the history
  4. Adding InternalUtilities to SK-dotnet.sln

    name committed Jun 16, 2023
    Configuration menu
    Copy the full SHA
    8bf200f View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    b8c905c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    3329af9 View commit details
    Browse the repository at this point in the history