All files / src/services/api/routers SkillsetRouter.tsx

88.88% Statements 32/36
76.47% Branches 13/17
100% Functions 10/10
88.88% Lines 32/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116                                          2209x         2209x     53x       53x 53x         2209x 7x 7x 7x         2209x       3x 3x 3x         2209x       3x 3x 3x         2209x 3x 3x     2209x 3x     3x     2209x 3x 3x                 2209x         3x         3x     2209x     3x       3x      
import {
  CreateSkillsetFromConfigRequest,
  CreateSkillsetFromConfigResponse,
  GenerateSkillsetRequest,
  SkillsetGenerationProposal,
} from "@/objects/SkillsetSetup";
import { Skillset } from "@/objects/Skillset";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { HistoricalAPIRouter } from "../HistoricalApiRouter";
 
/** Client for /app/skillsets — named bundles of skills that can be attached
 *  to agents as one unit. Tools/MCP servers are bundled the same way via
 *  /app/toolkits instead (see ToolkitRouter). */
export class SkillsetRouter extends HistoricalAPIRouter {
  constructor(
    host: string,
    token: string | null = null,
    default_config: AxiosRequestConfig | null = null,
    headers: Dictionary<string> = {},
  ) {
    super("skillsets", host, token, default_config, headers);
  }
 
  /** `includeSystem` adds the platform's built-in skillsets — for the
   *  Skillsets page and the pickers that grant a skillset to an agent. */
  list = async ({
    includeSystem = false,
  }: { includeSystem?: boolean } = {}): Promise<Skillset[]> => {
    const res = await this.api.get<Skillset[]>(
      this.prefix,
      includeSystem ? { params: { include_system: true } } : undefined,
    );
    Eif (super.validRes(res)) {
      return res.data;
    }
    return [];
  };
 
  getById = async (id: string): Promise<Skillset | null> => {
    const res = await this.api.get<Skillset>(this.endpoint(id));
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  create = async (body: {
    name: string;
    description?: string;
  }): Promise<Skillset | null> => {
    const res = await this.api.post<Skillset>(this.prefix, body);
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  update = async (
    id: string,
    body: { name?: string; description?: string },
  ): Promise<Skillset | null> => {
    const res = await this.api.patch<Skillset>(this.endpoint(id), body);
    Eif (super.validRes(res)) {
      return res.data;
    }
    return null;
  };
 
  delete = async (id: string): Promise<boolean> => {
    const res = await this.api.delete(this.endpoint(id));
    return res.status === 204;
  };
 
  addSkill = async (id: string, skillId: string): Promise<boolean> => {
    const res = await this.api.post(this.endpoint(`${id}/skills`), {
      skill_id: skillId,
    });
    return super.validRes(res);
  };
 
  removeSkill = async (id: string, skillId: string): Promise<boolean> => {
    const res = await this.api.delete(this.endpoint(`${id}/skills/${skillId}`));
    return res.status === 204;
  };
 
  // ── Generative setup ───────────────────────────────────────────────────────
  //
  // Skills-only: unlike the agent generative wizard, this flow has no tool
  // or MCP-server catalog/field at all — a generated skillset can never
  // bundle either.
 
  generateConfig = async (
    body: GenerateSkillsetRequest,
  ): Promise<SkillsetGenerationProposal> => {
    // Generation is a single long LLM call (30-90s); spread the default
    // config so withCredentials survives the per-request timeout override.
    const res = await this.api.post<SkillsetGenerationProposal>(
      this.endpoint("generate"),
      body,
      { ...(this.api.default_config ?? {}), timeout: 180000 },
    );
    return res.data;
  };
 
  createFromConfig = async (
    body: CreateSkillsetFromConfigRequest,
  ): Promise<CreateSkillsetFromConfigResponse> => {
    const res = await this.api.post<CreateSkillsetFromConfigResponse>(
      this.endpoint("create-from-config"),
      body,
    );
    return res.data;
  };
}