Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 28fa723

Browse files
jjaffeuxromanrizzi
andauthored
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 <[email protected]>
1 parent f43137e commit 28fa723

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

assets/javascripts/discourse/admin/models/ai-persona.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export default class AiPersona extends RestModel {
7777

7878
flattenedToolStructure(data) {
7979
return (data.tools || []).map((tName) => {
80-
return [tName, data.toolOptions[tName], data.forcedTools.includes(tName)];
80+
return [
81+
tName,
82+
data.toolOptions[tName] || {},
83+
data.forcedTools.includes(tName),
84+
];
8185
});
8286
}
8387

assets/javascripts/discourse/components/ai-persona-editor.gjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default class PersonaEditor extends Component {
3030

3131
@tracked allGroups = [];
3232
@tracked isSaving = false;
33-
@tracked availableForcedTools = [];
3433

3534
dirtyFormData = null;
3635

@@ -208,10 +207,6 @@ export default class PersonaEditor extends Component {
208207
toolOptions: updatedOptions,
209208
});
210209

211-
this.availableForcedTools = this.allTools.filter((tool) =>
212-
updatedTools.includes(tool.id)
213-
);
214-
215210
if (currentData.forcedTools?.length > 0) {
216211
const updatedForcedTools = currentData.forcedTools.filter(
217212
(fct) => !removedTools.includes(fct)
@@ -220,6 +215,11 @@ export default class PersonaEditor extends Component {
220215
}
221216
}
222217

218+
@action
219+
availableForcedTools(tools) {
220+
return this.allTools.filter((tool) => tools.includes(tool.id));
221+
}
222+
223223
mapToolOptions(currentOptions, toolNames) {
224224
const updatedOptions = Object.assign({}, currentOptions);
225225

@@ -439,7 +439,7 @@ export default class PersonaEditor extends Component {
439439
@value={{field.value}}
440440
@disabled={{data.system}}
441441
@onChange={{field.set}}
442-
@content={{this.availableForcedTools}}
442+
@content={{this.availableForcedTools data.tools}}
443443
/>
444444
</field.Custom>
445445
</form.Field>

spec/system/admin_ai_persona_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
tool_selector = PageObjects::Components::SelectKit.new("#control-tools .select-kit")
2828
tool_selector.expand
2929
tool_selector.select_row_by_value("Read")
30+
tool_selector.select_row_by_value("ListCategories")
3031
tool_selector.collapse
3132

3233
tool_selector = PageObjects::Components::SelectKit.new("#control-forcedTools .select-kit")
3334
tool_selector.expand
35+
tool_selector.select_row_by_value("ListCategories")
3436
tool_selector.select_row_by_value("Read")
3537
tool_selector.collapse
3638

@@ -46,8 +48,10 @@
4648
expect(persona.name).to eq("Test Persona")
4749
expect(persona.description).to eq("I am a test persona")
4850
expect(persona.system_prompt).to eq("You are a helpful bot")
49-
expect(persona.tools).to eq([["Read", { "read_private" => nil }, true]])
5051
expect(persona.forced_tool_count).to eq(1)
52+
53+
expected_tools = [["Read", { "read_private" => nil }, true], ["ListCategories", {}, true]]
54+
expect(persona.tools).to contain_exactly(*expected_tools)
5155
end
5256

5357
it "will not allow deletion or editing of system personas" do

0 commit comments

Comments
 (0)