Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(skills): populate slash menu and skills modal (#362)

Vasco Schiavoa998f88b723d
diff --git a/__tests__/components/modals/skills/skill-modal.test.tsx b/__tests__/components/modals/skills/skill-modal.test.tsx
index a7f61bf748..f8d707a615 100644
--- a/__tests__/components/modals/skills/skill-modal.test.tsx
+++ b/__tests__/components/modals/skills/skill-modal.test.tsx
@@ -3,67 +3,43 @@ import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { renderWithProviders } from "test-utils";
import { SkillsModal } from "#/components/features/conversation-panel/skills-modal";
-import { loadSkillsForConversation } from "#/api/agent-server-adapter";
+import SkillsService from "#/api/skills-service";
import { AgentState } from "#/types/agent-state";
import { useAgentState } from "#/hooks/use-agent-state";
-vi.mock("#/api/agent-server-adapter", () => ({
- loadSkillsForConversation: vi.fn(),
-}));
-
-// Mock the agent state hook
vi.mock("#/hooks/use-agent-state", () => ({
useAgentState: vi.fn(),
}));
-// Mock the conversation ID hook
-vi.mock("#/hooks/use-conversation-id", () => ({
- useConversationId: () => ({ conversationId: "test-conversation-id" }),
-}));
-
-// Mock useActiveConversation to provide execution_status
-vi.mock("#/hooks/query/use-active-conversation", () => ({
- useActiveConversation: () => ({
- data: {
- execution_status: "IDLE",
- },
- }),
-}));
-
describe("SkillsModal", () => {
const mockOnClose = vi.fn();
- const conversationId = "test-conversation-id";
const defaultProps = {
onClose: mockOnClose,
- conversationId,
};
const mockSkills = [
{
name: "Test Skill 1",
type: "repo" as const,
+ source: null,
triggers: ["test", "example"],
content: "This is test content for skill 1",
},
{
name: "Test Skill 2",
type: "knowledge" as const,
+ source: null,
triggers: ["help", "support"],
content: "This is test content for skill 2",
},
];
beforeEach(() => {
- // Reset all mocks before each test
vi.clearAllMocks();
- // Setup default mock for skills loading
- vi.mocked(loadSkillsForConversation).mockResolvedValue({
- skills: mockSkills,
- });
+ vi.spyOn(SkillsService, "getSkills").mockResolvedValue(mockSkills);
- // Mock the agent state to return a ready state
vi.mocked(useAgentState).mockReturnValue({
curAgentState: AgentState.AWAITING_USER_INPUT,
});
@@ -77,7 +53,6 @@ describe("SkillsModal", () => {
it("should render the refresh button with correct text and test ID", async () => {
renderWithProviders(<SkillsModal {...defaultProps} />);
- // Wait for the component to load and render the refresh button
const refreshButton = await screen.findByTestId("refresh-skills");
expect(refreshButton).toBeInTheDocument();
expect(refreshButton).toHaveTextContent("BUTTON$REFRESH");
@@ -87,38 +62,29 @@ describe("SkillsModal", () => {
describe("Refresh Button Functionality", () => {
it("should call refetch when refresh button is clicked", async () => {
const user = userEvent.setup();
- const refreshSpy = vi.mocked(loadSkillsForConversation);
+ const refreshSpy = vi.spyOn(SkillsService, "getSkills");
renderWithProviders(<SkillsModal {...defaultProps} />);
- // Wait for the component to load and render the refresh button
const refreshButton = await screen.findByTestId("refresh-skills");
- // Clear previous calls to only track the click
refreshSpy.mockClear();
await user.click(refreshButton);
- // Verify the refresh triggered a new API call
expect(refreshSpy).toHaveBeenCalled();
});
});
describe("Skills Display", () => {
it("should display skills correctly", async () => {
- vi.mocked(loadSkillsForConversation).mockResolvedValue({
- skills: mockSkills,
- });
+ vi.spyOn(SkillsService, "getSkills").mockResolvedValue(mockSkills);
renderWithProviders(<SkillsModal {...defaultProps} />);
- // Wait for skills to be loaded
await screen.findByText("Test Skill 1");
expect(screen.getByText("Test Skill 1")).toBeInTheDocument();
expect(screen.getByText("Test Skill 2")).toBeInTheDocument();
});
});
});
-
-// Note: Tests for deprecated API and removed settings were removed as the component
-// now uses agent-server API exclusively via useConversationSkills hook
diff --git a/__tests__/hooks/chat/use-slash-command.test.ts b/__tests__/hooks/chat/use-slash-command.test.ts
index 99a69b9e63..4b2dc846a0 100644
--- a/__tests__/hooks/chat/use-slash-command.test.ts
+++ b/__tests__/hooks/chat/use-slash-command.test.ts
@@ -19,6 +19,10 @@ const mockConversation = vi.hoisted(() => ({
data: undefined as { conversation_version?: "V0" | "V1" } | undefined,
}));
+vi.mock("#/hooks/query/use-skills", () => ({
+ useSkills: () => mockSkills,
+}));
+
const mockLlmProfiles = vi.hoisted(() => ({
data: undefined as
| {
diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.ts
index 10800e56bd..f7f9885a2f 100644
--- a/src/api/agent-server-adapter.ts
+++ b/src/api/agent-server-adapter.ts
@@ -1,21 +1,16 @@
-import { SkillsClient } from "@openhands/typescript-client/clients";
import { DEFAULT_SETTINGS } from "#/services/settings";
import { ExecutionStatus } from "#/types/agent-server/core";
import { Settings, SettingsValue } from "#/types/settings";
import { isAgentServerToolAvailable } from "./agent-server-compatibility";
-import {
- getAgentServerWorkingDir,
- shouldLoadPublicSkills,
-} from "./agent-server-config";
+import { getAgentServerWorkingDir } from "./agent-server-config";
import { getEffectiveLocalBackend } from "./backend-registry/active-store";
import { buildAuthHeaders } from "./backend-registry/auth";
import {
- GetSkillsResponse,
+ GetHooksResponse,
PluginSpec,
AppConversation,
AppConversationPage,
} from "./conversation-service/agent-server-conversation-service.types";
-import { getAgentServerClientOptions } from "./agent-server-client-options";
import SettingsService from "./settings-service/settings-service.api";
import { getStoredConversationMetadata } from "./conversation-metadata-store";
@@ -318,7 +313,7 @@ function createAgentFromSettings(agentSettings: SettingsRecord) {
kind: "Agent",
...agentSettings,
agent_context: {
- load_public_skills: shouldLoadPublicSkills(),
+ load_public_skills: true,
load_user_skills: true,
},
};
@@ -542,21 +537,6 @@ export async function buildStartConversationRequestWithEncryptedSettings(options
});
}
-export async function loadSkillsForConversation(
- conversation: AppConversation | null | undefined,
-): Promise<GetSkillsResponse> {
- const projectDir =
- conversation?.workspace?.working_dir ?? getAgentServerWorkingDir();
-
- const response = await new SkillsClient(
- getAgentServerClientOptions(),
- ).getSkills({
- load_public: shouldLoadPublicSkills(),
- load_user: true,
- load_project: true,
- load_org: false,
- project_dir: projectDir,
- });
-
- return { skills: response.skills ?? [] };
+export function emptyHooksResponse(): GetHooksResponse {
+ return { hooks: [] };
}
diff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.ts
index 74c0af4629..38444ada29 100644
--- a/src/api/conversation-service/agent-server-conversation-service.api.ts
+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts
@@ -29,6 +29,7 @@ import {
import {
DirectConversationInfo,
buildStartConversationRequestWithEncryptedSettings,
+ emptyHooksResponse,
getDefaultConversationTitle,
toAppConversation,
toConversationPage,
@@ -43,6 +44,7 @@ import {
setStoredConversationMetadata,
} from "../conversation-metadata-store";
import type {
+ GetHooksResponse,
PluginSpec,
AppConversation,
AppConversationPage,
@@ -478,6 +480,13 @@ class AgentServerConversationService {
);
}
+ static async getHooks(conversationId: string): Promise<GetHooksResponse> {
+ if (!conversationId) {
+ return emptyHooksResponse();
+ }
+ return emptyHooksResponse();
+ }
+
static async getRuntimeConversation(
conversationId: string,
conversationUrl: string | null | undefined,
diff --git a/src/components/features/chat/components/slash-command-menu.tsx b/src/components/features/chat/components/slash-command-menu.tsx
index c68636444a..4a8cdf0a9a 100644
--- a/src/components/features/chat/components/slash-command-menu.tsx
+++ b/src/components/features/chat/components/slash-command-menu.tsx
@@ -84,10 +84,15 @@ function SlashCommandMenuItem({
onSelect,
ref,
}: SlashCommandMenuItemProps) {
- const description = useMemo(
- () => (item.skill.content ? getSkillDescription(item.skill.content) : null),
- [item.skill.content],
- );
+ const description = useMemo(() => {
+ if ("content" in item.skill && item.skill.content) {
+ return getSkillDescription(item.skill.content);
+ }
+ if ("description" in item.skill && item.skill.description) {
+ return stripMarkdown(item.skill.description);
+ }
+ return null;
+ }, [item.skill]);
return (
<button
diff --git a/src/components/features/conversation-panel/skill-item.tsx b/src/components/features/conversation-panel/skill-item.tsx
index b7fd44f4ea..59867b6406 100644
--- a/src/components/features/conversation-panel/skill-item.tsx
+++ b/src/components/features/conversation-panel/skill-item.tsx
@@ -2,10 +2,10 @@ import { ChevronDown, ChevronRight } from "lucide-react";
import { Typography } from "#/ui/typography";
import { SkillTriggers } from "./skill-triggers";
import { SkillContent } from "./skill-content";
-import { Skill } from "#/api/conversation-service/agent-server-conversation-service.types";
+import { SkillInfo } from "#/types/settings";
interface SkillItemProps {
- skill: Skill;
+ skill: SkillInfo & { content?: string };
isExpanded: boolean;
onToggle: (agentName: string) => void;
}
@@ -48,8 +48,8 @@ export function SkillItem({ skill, isExpanded, onToggle }: SkillItemProps) {
{isExpanded && (
<div className="px-2 pb-3 pt-1">
- <SkillTriggers triggers={skill.triggers} />
- <SkillContent content={skill.content} />
+ <SkillTriggers triggers={skill.triggers ?? []} />
+ <SkillContent content={skill.content ?? ""} />
</div>
)}
</div>
diff --git a/src/components/features/conversation-panel/skills-modal.tsx b/src/components/features/conversation-panel/skills-modal.tsx
index 01f5ccd3a8..b0f3b92b0c 100644
--- a/src/components/features/conversation-panel/skills-modal.tsx
+++ b/src/components/features/conversation-panel/skills-modal.tsx
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
import { ModalBody } from "#/components/shared/modals/modal-body";
import { I18nKey } from "#/i18n/declaration";
-import { useConversationSkills } from "#/hooks/query/use-conversation-skills";
+import { useSkills } from "#/hooks/query/use-skills";
import { AgentState } from "#/types/agent-state";
import { Typography } from "#/ui/typography";
import { SkillsModalHeader } from "./skills-modal-header";
@@ -28,7 +28,7 @@ export function SkillsModal({ onClose }: SkillsModalProps) {
isError,
refetch,
isRefetching,
- } = useConversationSkills();
+ } = useSkills();
const toggleAgent = (agentName: string) => {
setExpandedAgents((prev) => ({
diff --git a/src/hooks/chat/use-slash-command.ts b/src/hooks/chat/use-slash-command.ts
index 5b8fa6dd5c..a072cacdd7 100644
--- a/src/hooks/chat/use-slash-command.ts
+++ b/src/hooks/chat/use-slash-command.ts
@@ -1,12 +1,12 @@
import { useState, useCallback, useEffect, useMemo, useRef } from "react";
-import { useConversationSkills } from "#/hooks/query/use-conversation-skills";
-import { Skill } from "#/api/conversation-service/agent-server-conversation-service.types";
+import { useSkills } from "#/hooks/query/use-skills";
+import { SkillInfo } from "#/types/settings";
import { Microagent } from "#/api/open-hands.types";
import { BUILT_IN_COMMANDS, MODEL_COMMAND } from "#/utils/constants";
import { useActiveBackend } from "#/contexts/active-backend-context";
import { useLlmProfiles } from "#/hooks/query/use-llm-profiles";
-export type SlashCommandSkill = Skill | Microagent;
+export type SlashCommandSkill = SkillInfo | Microagent;
export interface SlashCommandItem {
skill: SlashCommandSkill;
@@ -35,7 +35,7 @@ function getCursorOffset(element: HTMLElement): number {
export const useSlashCommand = (
chatInputRef: React.RefObject<HTMLDivElement | null>,
) => {
- const { data: skills, isLoading: isSkillsLoading } = useConversationSkills();
+ const { data: skills, isLoading: isSkillsLoading } = useSkills();
const isCloud = useActiveBackend().backend.kind === "cloud";
const { data: profilesData, isLoading: isProfilesLoading } = useLlmProfiles({
enabled: !isCloud,
diff --git a/src/hooks/query/use-conversation-skills.ts b/src/hooks/query/use-conversation-skills.ts
deleted file mode 100644
index 4d8822fdd2..0000000000
--- a/src/hooks/query/use-conversation-skills.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { useQuery } from "@tanstack/react-query";
-import { loadSkillsForConversation } from "#/api/agent-server-adapter";
-import { useConversationId } from "../use-conversation-id";
-import { useActiveConversation } from "./use-active-conversation";
-
-export const useConversationSkills = () => {
- const { conversationId } = useConversationId();
- const activeConversation = useActiveConversation().data;
- const executionStatus = activeConversation?.execution_status;
-
- return useQuery({
- queryKey: ["conversation", conversationId, "skills", activeConversation],
- queryFn: async () => {
- if (!conversationId) {
- throw new Error("No conversation ID provided");
- }
-
- const data = await loadSkillsForConversation(activeConversation);
- return data.skills;
- },
- enabled: !!executionStatus,
- staleTime: 1000 * 60 * 5, // 5 minutes
- gcTime: 1000 * 60 * 15, // 15 minutes
- });
-};
diff --git a/src/types/settings.ts b/src/types/settings.ts
index cdaf3b1ac0..97a78b0fff 100644
--- a/src/types/settings.ts
+++ b/src/types/settings.ts
@@ -104,6 +104,7 @@ export type SkillInfo = {
allowed_tools?: string[] | null;
is_agentskills_format?: boolean;
disable_model_invocation?: boolean;
+ content?: string;
};
export type SettingsScope = "personal";