Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(skills): an imported skill that is on shows as on, so one click turns it off

AdityaUmalef32ce4818519
diff --git a/src/components/bot-settings/SkillsSection.test.ts b/src/components/bot-settings/SkillsSection.test.ts
new file mode 100644
index 0000000000..0587f03e65
--- /dev/null
+++ b/src/components/bot-settings/SkillsSection.test.ts
@@ -0,0 +1,36 @@
+import { afterAll, describe, expect, it, vi } from "vitest";
+
+import type { ManagedSkill } from "./SkillsSection";
+
+// The settings components read `window` when they load; the src suite runs without one.
+vi.hoisted(() => {
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("localStorage", { getItem: () => null, setItem: () => {} });
+});
+afterAll(() => vi.unstubAllGlobals());
+
+const { skillSwitchOn } = await import("./SkillsSection");
+
+const imported = (fields: Partial<ManagedSkill>): ManagedSkill => ({
+ name: "cli-jira",
+ description: "Jira from the command line",
+ enabled: true,
+ source: "imported",
+ warnings: [],
+ origin: "imported",
+ ...fields,
+});
+
+describe("an imported skill's switch", () => {
+ it("is on for a skill that is on and in the bot's list", () => {
+ expect(skillSwitchOn(imported({ listed: true }))).toBe(true);
+ });
+
+ it("is on for a skill that is on but found only when a task needs it, so one click turns it off", () => {
+ expect(skillSwitchOn(imported({ listed: false }))).toBe(true);
+ });
+
+ it("is off for a skill that is off", () => {
+ expect(skillSwitchOn(imported({ enabled: false, listed: false }))).toBe(false);
+ });
+});
diff --git a/src/components/bot-settings/SkillsSection.tsx b/src/components/bot-settings/SkillsSection.tsx
index 83128a2a05..961943e7f8 100644
--- a/src/components/bot-settings/SkillsSection.tsx
+++ b/src/components/bot-settings/SkillsSection.tsx
@@ -26,8 +26,9 @@ export interface ManagedSkill {
listed?: boolean;
}
-/** A skill's switch: for one from this computer, whether it is in the bot's list. */
-export const skillSwitchOn = (skill: ManagedSkill): boolean => skill.enabled && skill.listed !== false;
+/** A skill's switch: on whenever the skill is on, including an imported one the bot finds only when a task needs it,
+ * so one click always turns it fully off. */
+export const skillSwitchOn = (skill: ManagedSkill): boolean => skill.enabled;
interface LibraryPoolSkill {
name: string;
@@ -133,13 +134,7 @@ export function useManagedSkills(bot: Bot) {
await refresh();
return;
}
- if (!skill.enabled || !skillSwitchOn(skill)) {
- if (skill.enabled) {
- // Already on, found when a task needs it: switching it on only puts it in the bot's list.
- await api(`/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}`, { method: "PATCH", body: JSON.stringify({ enabled: true }) });
- await refresh();
- return;
- }
+ if (!skill.enabled) {
// Security: a disabled import has not necessarily been reviewed; its integrity-checked bytes need one explicit
// review before they reach the prompt.
const result = (await api(skill.origin === "library" ? `/api/skills-library/${encodeURIComponent(skill.name)}` : `/api/bots/${bot.id}/skills/${encodeURIComponent(skill.name)}`)) as { text?: string };
@@ -494,7 +489,7 @@ export function SkillsSection({ bot }: { bot: Bot }) {
</span>
)}
<div className="mt-0.5 line-clamp-2 text-[12px] text-ink-secondary">{skill.description}</div>
- <div className="mt-0.5 text-[11px] text-ink-secondary">{t(skill.enabled && !skillSwitchOn(skill) ? "skills.foundWhenNeeded" : "skills.usedWhenRelevant")}</div>
+ <div className="mt-0.5 text-[11px] text-ink-secondary">{t(skill.enabled && skill.listed === false ? "skills.foundWhenNeeded" : "skills.usedWhenRelevant")}</div>
</button>
<Switch
checked={skillSwitchOn(skill)}