FIX: forced tools wasn't set correctly when tool has no options. (#1231)

* wip: more dynamic availableForcedTools

* FIX: forced tools wasn't set correctly when tool has no options.

---------

Co-authored-by: Roman Rizzi <rizziromanalejandro@gmail.com>
This commit is contained in:
Joffrey JAFFEUX 2025-03-31 15:45:03 +02:00 committed by GitHub
parent f43137e067
commit 28fa723472
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View File

@ -77,7 +77,11 @@ export default class AiPersona extends RestModel {
flattenedToolStructure(data) { flattenedToolStructure(data) {
return (data.tools || []).map((tName) => { return (data.tools || []).map((tName) => {
return [tName, data.toolOptions[tName], data.forcedTools.includes(tName)]; return [
tName,
data.toolOptions[tName] || {},
data.forcedTools.includes(tName),
];
}); });
} }

View File

@ -30,7 +30,6 @@ export default class PersonaEditor extends Component {
@tracked allGroups = []; @tracked allGroups = [];
@tracked isSaving = false; @tracked isSaving = false;
@tracked availableForcedTools = [];
dirtyFormData = null; dirtyFormData = null;
@ -208,10 +207,6 @@ export default class PersonaEditor extends Component {
toolOptions: updatedOptions, toolOptions: updatedOptions,
}); });
this.availableForcedTools = this.allTools.filter((tool) =>
updatedTools.includes(tool.id)
);
if (currentData.forcedTools?.length > 0) { if (currentData.forcedTools?.length > 0) {
const updatedForcedTools = currentData.forcedTools.filter( const updatedForcedTools = currentData.forcedTools.filter(
(fct) => !removedTools.includes(fct) (fct) => !removedTools.includes(fct)
@ -220,6 +215,11 @@ export default class PersonaEditor extends Component {
} }
} }
@action
availableForcedTools(tools) {
return this.allTools.filter((tool) => tools.includes(tool.id));
}
mapToolOptions(currentOptions, toolNames) { mapToolOptions(currentOptions, toolNames) {
const updatedOptions = Object.assign({}, currentOptions); const updatedOptions = Object.assign({}, currentOptions);
@ -439,7 +439,7 @@ export default class PersonaEditor extends Component {
@value={{field.value}} @value={{field.value}}
@disabled={{data.system}} @disabled={{data.system}}
@onChange={{field.set}} @onChange={{field.set}}
@content={{this.availableForcedTools}} @content={{this.availableForcedTools data.tools}}
/> />
</field.Custom> </field.Custom>
</form.Field> </form.Field>

View File

@ -27,10 +27,12 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do
tool_selector = PageObjects::Components::SelectKit.new("#control-tools .select-kit") tool_selector = PageObjects::Components::SelectKit.new("#control-tools .select-kit")
tool_selector.expand tool_selector.expand
tool_selector.select_row_by_value("Read") tool_selector.select_row_by_value("Read")
tool_selector.select_row_by_value("ListCategories")
tool_selector.collapse tool_selector.collapse
tool_selector = PageObjects::Components::SelectKit.new("#control-forcedTools .select-kit") tool_selector = PageObjects::Components::SelectKit.new("#control-forcedTools .select-kit")
tool_selector.expand tool_selector.expand
tool_selector.select_row_by_value("ListCategories")
tool_selector.select_row_by_value("Read") tool_selector.select_row_by_value("Read")
tool_selector.collapse tool_selector.collapse
@ -46,8 +48,10 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do
expect(persona.name).to eq("Test Persona") expect(persona.name).to eq("Test Persona")
expect(persona.description).to eq("I am a test persona") expect(persona.description).to eq("I am a test persona")
expect(persona.system_prompt).to eq("You are a helpful bot") expect(persona.system_prompt).to eq("You are a helpful bot")
expect(persona.tools).to eq([["Read", { "read_private" => nil }, true]])
expect(persona.forced_tool_count).to eq(1) expect(persona.forced_tool_count).to eq(1)
expected_tools = [["Read", { "read_private" => nil }, true], ["ListCategories", {}, true]]
expect(persona.tools).to contain_exactly(*expected_tools)
end end
it "will not allow deletion or editing of system personas" do it "will not allow deletion or editing of system personas" do