Renamed the settings of AI tasks (#1239)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-27 12:08:00 +01:00
1 parent d19d3d431b
commit a117074972
109 files changed
+3929 -538

No files matched your search

@@ -14,10 +14,10 @@ internal sealed class AssistantWebContentReader : StatefulAssistantComponentBase
set => this.Props[nameof(this.Preselect)] = value;
}
public bool PreselectContentCleanerAgent
public bool PreselectContentCleaner
{
get => this.Props.TryGetValue(nameof(this.PreselectContentCleanerAgent), out var v) && v is true;
set => this.Props[nameof(this.PreselectContentCleanerAgent)] = value;
get => this.Props.TryGetValue(nameof(this.PreselectContentCleaner), out var v) && v is true;
set => this.Props[nameof(this.PreselectContentCleaner)] = value;
}
public string Class
@@ -41,7 +41,7 @@ internal sealed class AssistantWebContentReader : StatefulAssistantComponentBase
state.WebContent[this.Name] = new WebContentState
{
Preselect = this.Preselect,
PreselectContentCleanerAgent = this.PreselectContentCleanerAgent,
PreselectContentCleaner = this.PreselectContentCleaner,
};
}
}
@@ -77,8 +77,13 @@ public static class ComponentPropSpecs
),
[AssistantComponentType.WEB_CONTENT_READER] = new(
required: ["Name"],
optional: ["UserPrompt", "Preselect", "PreselectContentCleanerAgent", "Class", "Style"],
nonWriteable: ["Name", "UserPrompt", "Class", "Style" ]
optional: ["UserPrompt", "Preselect", "PreselectContentCleaner", "Class", "Style"],
nonWriteable: ["Name", "UserPrompt", "Class", "Style" ],
formerNames: new Dictionary<string, string>
{
// The name before v26.11.2, when the content cleaner was called an agent:
["PreselectContentCleanerAgent"] = "PreselectContentCleaner",
}
),
[AssistantComponentType.FILE_CONTENT_READER] = new(
required: ["Name"],
@@ -1,5 +1,7 @@
using System.Collections.Immutable;
using Lua;
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
public class PropSpec(
@@ -7,7 +9,8 @@ public class PropSpec(
IEnumerable<string> optional,
IEnumerable<string>? nonReadable = null,
IEnumerable<string>? nonWriteable = null,
IEnumerable<string>? confidential = null)
IEnumerable<string>? confidential = null,
IReadOnlyDictionary<string, string>? formerNames = null)
{
public ImmutableArray<string> Required { get; } = MaterializeDistinct(required);
public ImmutableArray<string> Optional { get; } = MaterializeDistinct(optional);
@@ -15,6 +18,56 @@ public class PropSpec(
public ImmutableArray<string> NonReadable { get; } = MaterializeDistinct((nonReadable ?? []).Concat(confidential ?? []));
public ImmutableArray<string> NonWriteable { get; } = MaterializeDistinct((nonWriteable ?? []).Concat(confidential ?? []));
/// <summary>
/// The current name of each prop which had another name before, by that former name.
/// </summary>
/// <remarks>
/// Plugins keep using a former name for good, also in the props their callbacks return: a plugin
/// which changes it needs a new security audit. When a plugin uses both names, the current one
/// wins. Callbacks see a prop under its current name only.
/// </remarks>
public ImmutableDictionary<string, string> FormerNames { get; } = (formerNames ?? ImmutableDictionary<string, string>.Empty).ToImmutableDictionary(StringComparer.Ordinal);
/// <summary>
/// Reads a prop from the props of a component, under its current name or under a former name
/// which the plugin still uses.
/// </summary>
/// <param name="propsTable">The props of the component, as the plugin defines them.</param>
/// <param name="name">The current name of the prop.</param>
/// <param name="value">The value of the prop, when the plugin defines it.</param>
/// <returns>True, when the plugin defines the prop.</returns>
public bool TryGetValue(LuaTable propsTable, string name, out LuaValue value)
{
if (propsTable.TryGetValue(name, out value))
return true;
foreach (var (formerName, currentName) in this.FormerNames)
if (string.Equals(currentName, name, StringComparison.Ordinal) && propsTable.TryGetValue(formerName, out value))
return true;
return false;
}
/// <summary>
/// Determines the current name of a prop which a plugin names in its props, e.g., in an update
/// a callback returns.
/// </summary>
/// <param name="name">The name the plugin uses.</param>
/// <param name="propsTable">The props in which the plugin uses the name.</param>
/// <param name="currentName">The current name of the prop. It is the given name, unless that is a former one.</param>
/// <returns>False, when the plugin uses a former name next to the current one, which wins.</returns>
public bool TryGetCurrentName(string name, LuaTable propsTable, out string currentName)
{
if (!this.FormerNames.TryGetValue(name, out var nameAfterRenaming))
{
currentName = name;
return true;
}
currentName = nameAfterRenaming;
return !propsTable.TryGetValue(currentName, out _);
}
private static ImmutableArray<string> MaterializeDistinct(IEnumerable<string> source)
{
return source.Distinct(StringComparer.Ordinal).ToImmutableArray();
@@ -769,7 +769,7 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
foreach (var key in spec.Required)
{
if (!propsTable.TryGetValue(key, out var luaVal))
if (!spec.TryGetValue(propsTable, key, out var luaVal))
{
LOGGER.LogWarning($"Component {type} missing required prop '{key}'.");
return false;
@@ -784,7 +784,7 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
foreach (var key in spec.Optional)
{
if (!propsTable.TryGetValue(key, out var luaVal))
if (!spec.TryGetValue(propsTable, key, out var luaVal))
continue;
if (!this.TryConvertComponentPropValue(type, key, luaVal, out var dotNetVal))
@@ -0,0 +1,94 @@
using Lua;
namespace AIStudio.Tools.PluginSystem;
/// <summary>
/// Reads seven settings of the AI tasks under the names they had in AI Studio v26.11.1.
/// </summary>
/// <remarks>
/// Compatibility shim, remove after 2027-05-26, see documentation/compatibility-shims/2026-11-ai-task-setting-names.md.
/// Version v26.11.2 took the word "agent" out of the names of these settings. An organization rolls out a
/// new version over weeks, and devices with v26.11.1 read only the former names. A configuration plugin
/// therefore keeps the former names meanwhile, or sets both.
/// </remarks>
public static class FormerSettingNames
{
private const string USER_OVERRIDE_SUFFIX = ".AllowUserOverride";
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(nameof(FormerSettingNames));
/// <summary>
/// The current name of each setting, by the name it had in AI Studio v26.11.1.
/// </summary>
/// <remarks>
/// The settings of the AI tasks which came after v26.11.1 have no former name here, because no
/// released version knew them.
/// </remarks>
internal static readonly IReadOnlyDictionary<string, string> CURRENT_NAMES = new Dictionary<string, string>(StringComparer.Ordinal)
{
["DataAgentDataSourceSelection.PreselectAgentOptions"] = "DataDataSourceSelection.PreselectOptions",
["DataAgentDataSourceSelection.PreselectedAgentProvider"] = "DataDataSourceSelection.PreselectedProvider",
["DataAgentRetrievalContextValidation.EnableRetrievalContextValidation"] = "DataRetrievalContextValidation.EnableRetrievalContextValidation",
["DataAgentRetrievalContextValidation.PreselectAgentOptions"] = "DataRetrievalContextValidation.PreselectOptions",
["DataAgentRetrievalContextValidation.PreselectedAgentProvider"] = "DataRetrievalContextValidation.PreselectedProvider",
["DataAgentRetrievalContextValidation.NumParallelValidations"] = "DataRetrievalContextValidation.NumParallelValidations",
["DataAssistantPluginAudit.PreselectedAgentProvider"] = "DataAssistantPluginAudit.PreselectedProvider",
};
/// <summary>
/// Copies the SETTINGS table of a configuration plugin and gives every setting it sets under a
/// former name its current name.
/// </summary>
/// <remarks>
/// A former name covers its <c>.AllowUserOverride</c> companion as well. When a plugin sets a
/// setting under both names, as it does while the devices of an organization run both versions,
/// the current name wins and the former one is left out.
/// </remarks>
/// <param name="settingsTable">The SETTINGS table of the plugin.</param>
/// <param name="pluginName">The name of the plugin, for the log.</param>
/// <param name="logHints">Whether to log a hint for each setting which the plugin sets under its former name only.</param>
/// <returns>A new table, which holds every setting under its current name.</returns>
public static LuaTable Resolve(LuaTable settingsTable, string pluginName, bool logHints)
{
var resolvedTable = new LuaTable();
var previousKey = LuaValue.Nil;
while (settingsTable.TryGetNext(previousKey, out var pair))
{
previousKey = pair.Key;
if (!pair.Key.TryRead<string>(out var settingName) || !TryGetCurrentName(settingName, out var currentName))
{
resolvedTable[pair.Key] = pair.Value;
continue;
}
if (settingsTable.TryGetValue(currentName, out _))
continue;
resolvedTable[currentName] = pair.Value;
if (logHints && !settingName.EndsWith(USER_OVERRIDE_SUFFIX, StringComparison.Ordinal))
LOG.LogWarning($"The configuration plugin '{pluginName}' sets '{settingName}', the name of the setting '{currentName}' before AI Studio v26.11.2. AI Studio reads the former name until May 2027. Set the setting under both names until every device runs v26.11.2 or newer, then under its new name only.");
}
return resolvedTable;
}
/// <summary>
/// Looks up the current name of a setting by its former name, the <c>.AllowUserOverride</c> companion included.
/// </summary>
/// <param name="settingName">The name the plugin uses.</param>
/// <param name="currentName">The current name, when the plugin uses a former name; otherwise empty.</param>
/// <returns>True, when the plugin uses a former name.</returns>
private static bool TryGetCurrentName(string settingName, out string currentName)
{
var isUserOverride = settingName.EndsWith(USER_OVERRIDE_SUFFIX, StringComparison.Ordinal);
var baseName = isUserOverride ? settingName[..^USER_OVERRIDE_SUFFIX.Length] : settingName;
if (!CURRENT_NAMES.TryGetValue(baseName, out var currentBaseName))
{
currentName = string.Empty;
return false;
}
currentName = isUserOverride ? $"{currentBaseName}{USER_OVERRIDE_SUFFIX}" : currentBaseName;
return true;
}
}
@@ -227,6 +227,10 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
return false;
}
// Compatibility shim, remove after 2027-05-26, see FormerSettingNames. Everything below reads the
// settings under their current names only:
settingsTable = FormerSettingNames.Resolve(settingsTable, this.Name, !dryRun);
if (!TryValidateMinimumProviderConfidenceConfiguration(settingsTable, out message))
return false;
@@ -409,25 +413,25 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
LOG.LogWarning("The upper bound of the pause between indexing steps configured by plugin {ConfigPluginId} is below its lower bound. The lower bound of {MinimumPauseSeconds} seconds wins.", this.Id, minimumPauseSeconds);
// Config: text content cleaner settings
ManagedConfiguration.TryProcessConfiguration(x => x.TextContentCleaner, x => x.PreselectAgentOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.TextContentCleaner, x => x.PreselectedAgentProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.TextContentCleaner, x => x.PreselectOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.TextContentCleaner, x => x.PreselectedProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.TextContentCleaner, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
// Config: data source selection settings
ManagedConfiguration.TryProcessConfiguration(x => x.AgentDataSourceSelection, x => x.PreselectAgentOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentDataSourceSelection, x => x.PreselectedAgentProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentDataSourceSelection, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.DataSourceSelection, x => x.PreselectOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.DataSourceSelection, x => x.PreselectedProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.DataSourceSelection, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
// Config: retrieval context validation settings
ManagedConfiguration.TryProcessConfiguration(x => x.AgentRetrievalContextValidation, x => x.EnableRetrievalContextValidation, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentRetrievalContextValidation, x => x.PreselectAgentOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentRetrievalContextValidation, x => x.PreselectedAgentProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentRetrievalContextValidation, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AgentRetrievalContextValidation, x => x.NumParallelValidations, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.RetrievalContextValidation, x => x.EnableRetrievalContextValidation, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.RetrievalContextValidation, x => x.PreselectOptions, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.RetrievalContextValidation, x => x.PreselectedProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.RetrievalContextValidation, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.RetrievalContextValidation, x => x.NumParallelValidations, this.Id, settingsTable, dryRun);
// Config: assistant plugin audit settings
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.RequireAuditBeforeActivation, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.PreselectedAgentProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.PreselectedProvider, Guid.Empty, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.MinimumProviderConfidence, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.MinimumLevel, this.Id, settingsTable, dryRun);
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantPluginAudit, x => x.BlockActivationBelowMinimum, this.Id, settingsTable, dryRun);