Skip to content

Commit

Permalink
allow plugins with no config options
Browse files Browse the repository at this point in the history
  • Loading branch information
shatfield4 committed Sep 9, 2024
1 parent cffb906 commit b53fa7c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { sentenceCase } from "text-case";
* @returns {object} - The inputs object
*/
function inputsFromArgs(setupArgs) {
if (!setupArgs || typeof setupArgs !== "object") {
return {};
}
return Object.entries(setupArgs).reduce(
(acc, [key, props]) => ({
...acc,
Expand All @@ -32,9 +35,13 @@ export default function ImportedSkillConfig({
const [config, setConfig] = useState(selectedSkill);
const [hasChanges, setHasChanges] = useState(false);
const [inputs, setInputs] = useState(
inputsFromArgs(selectedSkill.setup_args)
inputsFromArgs(selectedSkill?.setup_args)
);

const hasSetupArgs =
selectedSkill?.setup_args &&
Object.keys(selectedSkill.setup_args).length > 0;

async function toggleSkill() {
const updatedConfig = { ...selectedSkill, active: !config.active };
await System.experimentalFeatures.agentPlugins.updatePluginConfig(
Expand Down Expand Up @@ -122,41 +129,47 @@ export default function ImportedSkillConfig({
</a>
</p>

<div className="flex flex-col gap-y-2">
{Object.entries(config.setup_args).map(([key, props]) => (
<div key={key} className="flex flex-col gap-y-1">
<label htmlFor={key} className="text-white text-sm font-bold">
{key}
</label>
<input
type={props?.input?.type || "text"}
required={props?.input?.required}
defaultValue={
props.hasOwnProperty("value")
? props.value
: props?.input?.default || ""
}
onChange={(e) =>
setInputs({ ...inputs, [key]: e.target.value })
}
placeholder={props?.input?.placeholder || ""}
className="bg-transparent border border-white border-opacity-20 rounded-md p-2 text-white text-sm"
/>
<p className="text-white text-opacity-60 text-xs font-medium py-1.5">
{props?.input?.hint}
</p>
</div>
))}
{hasChanges && (
<button
onClick={handleSubmit}
type="button"
className="bg-blue-500 text-white rounded-md p-2"
>
Save
</button>
)}
</div>
{hasSetupArgs ? (
<div className="flex flex-col gap-y-2">
{Object.entries(config.setup_args).map(([key, props]) => (
<div key={key} className="flex flex-col gap-y-1">
<label htmlFor={key} className="text-white text-sm font-bold">
{key}
</label>
<input
type={props?.input?.type || "text"}
required={props?.input?.required}
defaultValue={
props.hasOwnProperty("value")
? props.value
: props?.input?.default || ""
}
onChange={(e) =>
setInputs({ ...inputs, [key]: e.target.value })
}
placeholder={props?.input?.placeholder || ""}
className="bg-transparent border border-white border-opacity-20 rounded-md p-2 text-white text-sm"
/>
<p className="text-white text-opacity-60 text-xs font-medium py-1.5">
{props?.input?.hint}
</p>
</div>
))}
{hasChanges && (
<button
onClick={handleSubmit}
type="button"
className="bg-blue-500 text-white rounded-md p-2"
>
Save
</button>
)}
</div>
) : (
<p className="text-white text-opacity-60 text-sm font-medium py-1.5">
There are no options to modify for this skill.
</p>
)}
</div>
</div>
</>
Expand Down
3 changes: 3 additions & 0 deletions server/utils/agents/imported.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class ImportedPlugin {

parseCallOptions() {
const callOpts = {};
if (!this.config.setup_args || typeof this.config.setup_args !== 'object') {
return callOpts;
}
for (const [param, definition] of Object.entries(this.config.setup_args)) {
if (definition.required && !definition?.value) {
console.log(
Expand Down

0 comments on commit b53fa7c

Please sign in to comment.