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

Commit 81129f7

Browse files
committed
FIX: when tool options are added they should be available
Fixes a regression where tool option editor was not showing all tools
1 parent c885e56 commit 81129f7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

assets/javascripts/discourse/components/ai-persona-tool-options.gjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ export default class AiPersonaToolOptions extends Component {
3333
return toolOptions ? Object.keys(toolOptions) : [];
3434
}
3535

36+
@action
37+
toolOptionKeys(toolId) {
38+
// this is important, some tools may not have all options defined (for example if a tool option is added)
39+
const metadata = this.toolsMetadata[toolId];
40+
if (!metadata) {
41+
return [];
42+
}
43+
44+
// a bit more verbose for clarity of our selection
45+
const availableOptions = Object.keys(metadata).filter((k) => k !== "name");
46+
return availableOptions;
47+
}
48+
3649
<template>
3750
{{#if this.showToolOptions}}
3851
<@form.Container
@@ -52,7 +65,7 @@ export default class AiPersonaToolOptions extends Component {
5265
{{toolMeta.name}}
5366
</div>
5467
<toolObj.Object @name={{toolId}} as |optionsObj optionData|>
55-
{{#each (this.formObjectKeys optionData) as |optionName|}}
68+
{{#each (this.toolOptionKeys toolId) as |optionName|}}
5669
{{#let (get toolMeta optionName) as |optionMeta|}}
5770
<optionsObj.Field
5871
@name={{optionName}}

spec/system/admin_ai_persona_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@
5151

5252
expected_tools = [["Read", { "read_private" => nil }, true], ["ListCategories", {}, true]]
5353
expect(persona.tools).to contain_exactly(*expected_tools)
54+
55+
# lets also test upgrades here... particularly one options was deleted and another added
56+
# this ensurse that we can still edit the tool correctly and all options are present
57+
persona.update!(tools: [["Read", { "got_deleted" => true }]])
58+
59+
visit "/admin/plugins/discourse-ai/ai-personas/#{persona_id}/edit"
60+
61+
expect(page).to have_selector("input[name='toolOptions.Read.read_private']")
62+
expect(page).not_to have_selector("input[name='toolOptions.Read.got_deleted']")
5463
end
5564

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

0 commit comments

Comments
 (0)