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

FIX: when tool options are added they should be available #1406

Merged
merged 2 commits into from
Jun 5, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export default class AiPersonaToolOptions extends Component {
return toolOptions ? Object.keys(toolOptions) : [];
}

@action
toolOptionKeys(toolId) {
// this is important, some tools may not have all options defined (for example if a tool option is added)
const metadata = this.toolsMetadata[toolId];
if (!metadata) {
return [];
}

// a bit more verbose for clarity of our selection
const availableOptions = Object.keys(metadata).filter((k) => k !== "name");
return availableOptions;
}

<template>
{{#if this.showToolOptions}}
<@form.Container
Expand All @@ -51,8 +64,8 @@ export default class AiPersonaToolOptions extends Component {
<div class="ai-persona-editor__tool-options-name">
{{toolMeta.name}}
</div>
<toolObj.Object @name={{toolId}} as |optionsObj optionData|>
{{#each (this.formObjectKeys optionData) as |optionName|}}
<toolObj.Object @name={{toolId}} as |optionsObj|>
{{#each (this.toolOptionKeys toolId) as |optionName|}}
{{#let (get toolMeta optionName) as |optionMeta|}}
<optionsObj.Field
@name={{optionName}}
Expand Down
9 changes: 9 additions & 0 deletions spec/system/admin_ai_persona_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@

expected_tools = [["Read", { "read_private" => nil }, true], ["ListCategories", {}, true]]
expect(persona.tools).to contain_exactly(*expected_tools)

# lets also test upgrades here... particularly one options was deleted and another added
# this ensurse that we can still edit the tool correctly and all options are present
persona.update!(tools: [["Read", { "got_deleted" => true }]])

visit "/admin/plugins/discourse-ai/ai-personas/#{persona_id}/edit"

expect(page).to have_selector("input[name='toolOptions.Read.read_private']")
expect(page).not_to have_selector("input[name='toolOptions.Read.got_deleted']")
end

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