Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion assets/javascripts/discourse/admin/models/ai-persona.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export default class AiPersona extends RestModel {

flattenedToolStructure(data) {
return (data.tools || []).map((tName) => {
return [tName, data.toolOptions[tName], data.forcedTools.includes(tName)];
return [
tName,
data.toolOptions[tName] || {},
data.forcedTools.includes(tName),
];
});
}

Expand Down
12 changes: 6 additions & 6 deletions assets/javascripts/discourse/components/ai-persona-editor.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default class PersonaEditor extends Component {

@tracked allGroups = [];
@tracked isSaving = false;
@tracked availableForcedTools = [];

dirtyFormData = null;

Expand Down Expand Up @@ -208,10 +207,6 @@ export default class PersonaEditor extends Component {
toolOptions: updatedOptions,
});

this.availableForcedTools = this.allTools.filter((tool) =>
updatedTools.includes(tool.id)
);

if (currentData.forcedTools?.length > 0) {
const updatedForcedTools = currentData.forcedTools.filter(
(fct) => !removedTools.includes(fct)
Expand All @@ -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) {
const updatedOptions = Object.assign({}, currentOptions);

Expand Down Expand Up @@ -439,7 +439,7 @@ export default class PersonaEditor extends Component {
@value={{field.value}}
@disabled={{data.system}}
@onChange={{field.set}}
@content={{this.availableForcedTools}}
@content={{this.availableForcedTools data.tools}}
/>
</field.Custom>
</form.Field>
Expand Down
6 changes: 5 additions & 1 deletion spec/system/admin_ai_persona_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
tool_selector = PageObjects::Components::SelectKit.new("#control-tools .select-kit")
tool_selector.expand
tool_selector.select_row_by_value("Read")
tool_selector.select_row_by_value("ListCategories")
tool_selector.collapse

tool_selector = PageObjects::Components::SelectKit.new("#control-forcedTools .select-kit")
tool_selector.expand
tool_selector.select_row_by_value("ListCategories")
tool_selector.select_row_by_value("Read")
tool_selector.collapse

Expand All @@ -46,8 +48,10 @@
expect(persona.name).to eq("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.tools).to eq([["Read", { "read_private" => nil }, true]])
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

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