All files / src/apps/user/pages/agents/setup/steps ReviewSkillsStep.tsx

45.83% Statements 11/24
64.28% Branches 18/28
23.52% Functions 4/17
52.38% Lines 11/21

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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238                                  2x     14x 14x                                                       2x                                                   14x         14x 14x             14x                                           14x 14x                                                                                                               14x                                                                                                                                            
import BuiltInBadge from "@/components/badge/BuiltInBadge";
import { ProposedSkill, ProposedSkillsetInfo } from "@/objects/AgentSetup";
import { isSystemManaged } from "@/objects/Doc";
import { Skill } from "@/objects/Skill";
import { Skillset } from "@/objects/Skillset";
import {
  AlertTriangle,
  ChevronDown,
  ChevronRight,
  Layers3,
  Sparkles,
  Tag,
  Zap,
} from "lucide-react";
import React, { useState } from "react";
import { FieldLabel, SectionCard, ToggleRow, inputBase } from "../primitives";
 
const GraphPreview: React.FC<{ graph: Record<string, unknown> }> = ({
  graph,
}) => {
  const [open, setOpen] = useState(false);
  return (
    <div className="mt-2">
      <button
        type="button"
        onClick={() => setOpen((o) => !o)}
        className="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-colors"
      >
        {open ? (
          <ChevronDown className="size-3.5" />
        ) : (
          <ChevronRight className="size-3.5" />
        )}
        Workflow graph
      </button>
      {open && (
        <pre className="mt-2 p-3 rounded-lg bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 text-[11px] leading-relaxed text-gray-600 dark:text-gray-300 overflow-x-auto max-h-64">
          {JSON.stringify(graph, null, 2)}
        </pre>
      )}
    </div>
  );
};
 
// Agents only ever integrate skills through an attached skillset — never
// individually — so an existing skill the AI selected is purely
// informational here, and a skill this step creates is not itself granted
// to the agent; only existingSkillsets is togglable as a grant. The
// platform's built-in skillsets arrive among those, granted by reference.
const ReviewSkillsStep: React.FC<{
  existingSkills: Skill[];
  proposedSkills: ProposedSkill[];
  existingSkillsets: Skillset[];
  proposedSkillsets: ProposedSkillsetInfo[];
  includedProposed: Set<number>;
  includedExistingSkillsets: Set<string>;
  includedProposedSkillsets: Set<number>;
  onToggleProposed: (index: number) => void;
  onToggleExistingSkillset: (id: string) => void;
  onToggleProposedSkillset: (index: number) => void;
  onEditProposed: (index: number, skill: ProposedSkill) => void;
}> = ({
  existingSkills,
  proposedSkills,
  existingSkillsets,
  proposedSkillsets,
  includedProposed,
  includedExistingSkillsets,
  includedProposedSkillsets,
  onToggleProposed,
  onToggleExistingSkillset,
  onToggleProposedSkillset,
  onEditProposed,
}) => {
  const nothingSelected =
    existingSkills.length === 0 &&
    proposedSkills.length === 0 &&
    existingSkillsets.length === 0 &&
    proposedSkillsets.length === 0;
 
  const skillNameById = new Map(existingSkills.map((s) => [s.id, s.name]));
  const skillsetMemberNames = (skillset: ProposedSkillsetInfo): string[] => [
    ...skillset.member_skill_ids.map(
      (id) => skillNameById.get(id) ?? `Unknown (${id})`,
    ),
    ...skillset.member_proposed_skill_names.map((name) => `${name} (new)`),
  ];
 
  return (
    <div className="space-y-4">
      {nothingSelected && (
        <div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-5 py-8 text-center">
          <Zap className="size-5 text-gray-400 dark:text-gray-500 mx-auto mb-2" />
          <p className="text-sm text-gray-500 dark:text-gray-400">
            The AI didn't select or propose any skills for this use case. You
            can attach a skillset after the agent is created.
          </p>
        </div>
      )}
 
      {existingSkillsets.length > 0 && (
        <SectionCard
          icon={Layers3}
          title="Skillsets to attach"
          description="Existing bundles of skills — yours, or built into the platform — the AI recommends attaching as one unit. This is the only way this wizard grants an agent skill access. Untick any you don't want."
        >
          <div className="space-y-2">
            {existingSkillsets.map((skillset) => {
              // Guarded: a proposal from before the members were served
              // (or restored from this tab's storage) has none.
              const memberCount = (skillset.skill_ids ?? []).length;
              return (
                <ToggleRow
                  key={skillset.id}
                  title={skillset.name}
                  subtitle={skillset.description}
                  meta={
                    <>
                      {isSystemManaged(skillset) && <BuiltInBadge size="sm" />}
                      {`${memberCount} member${memberCount !== 1 ? "s" : ""}`}
                    </>
                  }
                  selected={includedExistingSkillsets.has(skillset.id)}
                  accent="amber"
                  onToggle={() => onToggleExistingSkillset(skillset.id)}
                />
              );
            })}
          </div>
        </SectionCard>
      )}
 
      {proposedSkillsets.length > 0 && (
        <SectionCard
          icon={Sparkles}
          title="New skillsets to create"
          description="Named collections grouping the skills below — this is the only way this wizard grants an agent skill access. Auto-attached to this agent on creation."
        >
          <div className="space-y-2">
            {proposedSkillsets.map((skillset, index) => (
              <ToggleRow
                key={index}
                title={skillset.name}
                subtitle={skillset.description}
                meta={
                  <>
                    <Layers3 className="size-3" />
                    {skillsetMemberNames(skillset).join(", ")}
                  </>
                }
                selected={includedProposedSkillsets.has(index)}
                accent="amber"
                onToggle={() => onToggleProposedSkillset(index)}
              />
            ))}
          </div>
        </SectionCard>
      )}
 
      {proposedSkills.length > 0 && (
        <SectionCard
          icon={Sparkles}
          title="New skills designed for you"
          description="Multi-step workflows the AI designed for this agent. Created in your workspace — not attached to this agent (add them to a skillset and attach that afterward). Rename or exclude them; advanced graph editing is available after creation."
        >
          <div className="space-y-2">
            {proposedSkills.map((skill, index) => (
              <ToggleRow
                key={index}
                title={skill.name}
                selected={includedProposed.has(index)}
                accent="amber"
                onToggle={() => onToggleProposed(index)}
              >
                {includedProposed.has(index) && (
                  <div className="mt-3 space-y-3">
                    <div>
                      <FieldLabel label="Name" required />
                      <input
                        type="text"
                        value={skill.name}
                        onChange={(e) =>
                          onEditProposed(index, {
                            ...skill,
                            name: e.target.value,
                          })
                        }
                        className={inputBase}
                      />
                    </div>
                    <div>
                      <FieldLabel label="Description" />
                      <textarea
                        value={skill.description}
                        onChange={(e) =>
                          onEditProposed(index, {
                            ...skill,
                            description: e.target.value,
                          })
                        }
                        rows={2}
                        className={inputBase + " resize-none"}
                      />
                    </div>
                    <GraphPreview graph={skill.graph_definition} />
                  </div>
                )}
              </ToggleRow>
            ))}
          </div>
        </SectionCard>
      )}
 
      {existingSkills.length > 0 && (
        <SectionCard
          icon={AlertTriangle}
          title="Not attachable directly"
          description="Agents only integrate skills through a skillset, not individually — these aren't included above. Add one to a skillset first if you want this agent to use it."
        >
          <div className="space-y-1.5">
            {existingSkills.map((skill) => (
              <div
                key={skill.id}
                className="flex items-center gap-2 text-xs text-gray-500 dark:text-gray-400"
              >
                <Tag className="size-3 shrink-0 text-gray-400" />
                {skill.name}
              </div>
            ))}
          </div>
        </SectionCard>
      )}
    </div>
  );
};
 
export default ReviewSkillsStep;