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

33.33% Statements 4/12
62.5% Branches 5/8
11.11% Functions 1/9
40% Lines 4/10

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                                  2x                                           2x           50x   50x                                                                                                                                                                                                                                                                      
import {
  AppearanceFields,
  appearanceOf,
  AppearanceSwatch,
} from "@/components/appearance/AppearancePicker";
import { AGENT_ICON_REGISTRY } from "@/components/appearance/icons";
import DiffViewer from "@/components/diff/DiffViewer/DiffViewer";
import { FieldDiff } from "@/objects/History";
import { ProposalAgent } from "@/objects/AgentSetup";
import { AlertTriangle, Bot, FileText, GitCompare, Info } from "lucide-react";
import React, { useState } from "react";
import { FieldLabel, SectionCard, inputBase } from "../primitives";
 
/** The proposal hasn't been persisted yet, so there's no prior version to
 * diff against โ€” every field simply renders as "added" against a blank
 * agent. This reuses the same git-style DiffViewer as a resource's edit
 * history, so review and history share one visual language. */
const proposalDiffFields = (agent: ProposalAgent): FieldDiff[] => [
  { field: "name", change_type: "added", old_value: null, new_value: agent.name },
  {
    field: "description",
    change_type: "added",
    old_value: null,
    new_value: agent.description,
  },
  {
    field: "appearance",
    change_type: "added",
    old_value: null,
    new_value: `${agent.icon} ยท ${agent.accent}`,
  },
  {
    field: "system_prompt",
    change_type: "added",
    old_value: null,
    new_value: agent.system_prompt,
  },
];
 
const ReviewIdentityStep: React.FC<{
  agent: ProposalAgent;
  reasoning: string;
  warnings: string[];
  onChange: (agent: ProposalAgent) => void;
}> = ({ agent, reasoning, warnings, onChange }) => {
  const [showDiff, setShowDiff] = useState(false);
 
  return (
  <div className="space-y-4">
    {reasoning && (
      <div className="rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 px-4 py-3">
        <div className="flex items-center gap-1.5 text-xs font-medium text-blue-700 dark:text-blue-300 mb-1">
          <Info className="size-3.5" />
          Why the AI designed it this way
        </div>
        <p className="text-xs text-blue-600 dark:text-blue-400 whitespace-pre-wrap">
          {reasoning}
        </p>
      </div>
    )}
 
    {warnings.length > 0 && (
      <div className="rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 px-4 py-3">
        <div className="flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-300 mb-1">
          <AlertTriangle className="size-3.5" />
          Generation notes
        </div>
        <ul className="space-y-1">
          {warnings.map((warning) => (
            <li
              key={warning}
              className="text-xs text-amber-600 dark:text-amber-400"
            >
              {warning}
            </li>
          ))}
        </ul>
      </div>
    )}
 
    <div className="flex justify-end">
      <button
        type="button"
        onClick={() => setShowDiff((v) => !v)}
        className="flex items-center gap-1.5 text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors"
      >
        <GitCompare className="size-3.5" />
        {showDiff ? "Edit fields" : "View as diff"}
      </button>
    </div>
 
    {showDiff ? (
      <SectionCard
        icon={GitCompare}
        title="Proposed Changes"
        description="A preview of what will be created, in the same git-style diff used to view a resource's later edit history."
      >
        <DiffViewer
          fields={proposalDiffFields(agent)}
          fieldLabels={{
            name: "Name",
            description: "Description",
            appearance: "Appearance",
            system_prompt: "System Prompt",
          }}
        />
      </SectionCard>
    ) : (
      <>
    <SectionCard
      icon={Bot}
      title="Identity"
      description="Review the generated name and description โ€” edit anything that doesn't fit."
    >
      <div>
        <FieldLabel label="Name" required />
        <input
          type="text"
          value={agent.name}
          onChange={(e) => onChange({ ...agent, name: e.target.value })}
          className={inputBase}
        />
      </div>
      <div>
        <FieldLabel label="Description" />
        <textarea
          value={agent.description}
          onChange={(e) => onChange({ ...agent, description: e.target.value })}
          rows={3}
          className={inputBase + " resize-none"}
        />
      </div>
      <div>
        <FieldLabel label="Appearance" />
        <div className="flex items-start gap-4">
          <AppearanceSwatch
            registry={AGENT_ICON_REGISTRY}
            icon={agent.icon}
            accent={agent.accent}
            size="lg"
          />
          <div className="flex-1 min-w-0">
            <AppearanceFields
              registry={AGENT_ICON_REGISTRY}
              labels={false}
              value={appearanceOf(
                AGENT_ICON_REGISTRY,
                agent.icon,
                agent.accent,
              )}
              onChange={(next) =>
                onChange({ ...agent, icon: next.icon, accent: next.accent })
              }
            />
          </div>
        </div>
      </div>
    </SectionCard>
 
    <SectionCard
      icon={FileText}
      title="System Prompt"
      description="The generated core instructions for the agent. Refine freely โ€” this is the heart of its behaviour."
    >
      <textarea
        value={agent.system_prompt}
        onChange={(e) => onChange({ ...agent, system_prompt: e.target.value })}
        rows={14}
        className={inputBase + " resize-y font-mono text-xs leading-relaxed"}
      />
    </SectionCard>
      </>
    )}
  </div>
  );
};
 
export default ReviewIdentityStep;