mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-23 16:12:21 +00:00
FIX: when tool options are added they should be available (#1406)
Fixes a regression where tool option editor was not showing all tools
This commit is contained in:
parent
c885e5697f
commit
b3d78a6a10
@ -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
|
||||
@ -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}}
|
||||
|
@ -51,6 +51,15 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user