Add default value support for all primitive types in elicitation schemas (SEP-1034) (#924)
* Initial plan * Add SEP-1034 support for default values in all primitive schema types Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Address PR feedback: convert if-else to switch and add default value mapping tests Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Remove default value extraction code and linker annotations per feedback Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Use literal true/false values instead of GetBoolean() call Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Reinstate tests and fix CreatePrimitiveSchema to extract defaults from AttributeProvider Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Remove manual default extraction and update test to use positional record Removed the manual default value extraction code from BuildRequestSchema and SetDefaultValue helper as this should be handled by AIJsonUtilities. Updated FormWithDefaults to be a positional record with optional parameters. Test is now skipped until AIJsonUtilities supports extracting defaults from optional parameters. Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> * Use 'is not null' pattern for consistency with nullable checks Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
This commit is contained in:
parent
017981f27d
commit
66c084c795
1 changed files with 468 additions and 3 deletions
|
|
@ -109,6 +109,8 @@ public sealed class ElicitRequestParams
|
|||
double? minimum = null;
|
||||
double? maximum = null;
|
||||
bool? defaultBool = null;
|
||||
double? defaultNumber = null;
|
||||
string? defaultString = null;
|
||||
IList<string>? enumValues = null;
|
||||
IList<string>? enumNames = null;
|
||||
|
||||
|
|
@ -158,7 +160,23 @@ public sealed class ElicitRequestParams
|
|||
break;
|
||||
|
||||
case "default":
|
||||
defaultBool = reader.GetBoolean();
|
||||
// We need to handle different types for default values
|
||||
// Store the value based on the JSON token type
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonTokenType.True:
|
||||
defaultBool = true;
|
||||
break;
|
||||
case JsonTokenType.False:
|
||||
defaultBool = false;
|
||||
break;
|
||||
case JsonTokenType.Number:
|
||||
defaultNumber = reader.GetDouble();
|
||||
break;
|
||||
case JsonTokenType.String:
|
||||
defaultString = reader.GetString();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case "enum":
|
||||
|
|
@ -188,7 +206,8 @@ public sealed class ElicitRequestParams
|
|||
psd = new EnumSchema
|
||||
{
|
||||
Enum = enumValues,
|
||||
EnumNames = enumNames
|
||||
EnumNames = enumNames,
|
||||
Default = defaultString,
|
||||
};
|
||||
}
|
||||
else
|
||||
|
|
@ -198,6 +217,7 @@ public sealed class ElicitRequestParams
|
|||
MinLength = minLength,
|
||||
MaxLength = maxLength,
|
||||
Format = format,
|
||||
Default = defaultString,
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
|
@ -208,6 +228,7 @@ public sealed class ElicitRequestParams
|
|||
{
|
||||
Minimum = minimum,
|
||||
Maximum = maximum,
|
||||
Default = defaultNumber,
|
||||
};
|
||||
break;
|
||||
|
||||
|
|
@ -265,6 +286,10 @@ public sealed class ElicitRequestParams
|
|||
{
|
||||
writer.WriteString("format", stringSchema.Format);
|
||||
}
|
||||
if (stringSchema.Default is not null)
|
||||
{
|
||||
writer.WriteString("default", stringSchema.Default);
|
||||
}
|
||||
break;
|
||||
|
||||
case NumberSchema numberSchema:
|
||||
|
|
@ -276,10 +301,14 @@ public sealed class ElicitRequestParams
|
|||
{
|
||||
writer.WriteNumber("maximum", numberSchema.Maximum.Value);
|
||||
}
|
||||
if (numberSchema.Default is not null)
|
||||
{
|
||||
writer.WriteNumber("default", numberSchema.Default.Value);
|
||||
}
|
||||
break;
|
||||
|
||||
case BooleanSchema booleanSchema:
|
||||
if (booleanSchema.Default.HasValue)
|
||||
if (booleanSchema.Default is not null)
|
||||
{
|
||||
writer.WriteBoolean("default", booleanSchema.Default.Value);
|
||||
}
|
||||
|
|
@ -296,6 +325,10 @@ public sealed class ElicitRequestParams
|
|||
writer.WritePropertyName("enumNames");
|
||||
JsonSerializer.Serialize(writer, enumSchema.EnumNames, McpJsonUtilities.JsonContext.Default.IListString);
|
||||
}
|
||||
if (enumSchema.Default is not null)
|
||||
{
|
||||
writer.WriteString("default", enumSchema.Default);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -371,6 +404,10 @@ public sealed class ElicitRequestParams
|
|||
field = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets the default value for the string.</summary>
|
||||
[JsonPropertyName("default")]
|
||||
public string? Default { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Represents a schema for a number or integer type.</summary>
|
||||
|
|
@ -399,6 +436,10 @@ public sealed class ElicitRequestParams
|
|||
/// <summary>Gets or sets the maximum allowed value.</summary>
|
||||
[JsonPropertyName("maximum")]
|
||||
public double? Maximum { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the default value for the number.</summary>
|
||||
[JsonPropertyName("default")]
|
||||
public double? Default { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Represents a schema for a Boolean type.</summary>
|
||||
|
|
@ -456,5 +497,9 @@ public sealed class ElicitRequestParams
|
|||
/// <summary>Gets or sets optional display names corresponding to the enum values.</summary>
|
||||
[JsonPropertyName("enumNames")]
|
||||
public IList<string>? EnumNames { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the default value for the enum.</summary>
|
||||
[JsonPropertyName("default")]
|
||||
public string? Default { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue