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

68.75% Statements 11/16
62.5% Branches 5/8
66.66% Functions 6/9
71.42% Lines 10/14

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            2x 9x 5x   5x             2x 5x   2x           10x                       9x                 9x                                                                                              
import { ProposedRule } from "@/objects/AgentSetup";
import { ruleLayerMeta } from "@/apps/user/pages/rules/ruleLayer";
import { Shield, Sparkles } from "lucide-react";
import React from "react";
import { FieldLabel, SectionCard, ToggleRow, inputBase } from "../primitives";
 
const conditionSummary = (rule: ProposedRule): string => {
  Iif (rule.conditions.length === 0) return "always";
  return rule.conditions
    .map((c) =>
      c.field === "always"
        ? "always"
        : `${c.field} ${c.operator} “${String(c.value)}”`,
    )
    .join(" AND ");
};
 
const actionSummary = (rule: ProposedRule): string =>
  rule.actions.map((a) => a.type).join(", ");
 
const ReviewRulesStep: React.FC<{
  proposedRules: ProposedRule[];
  includedProposed: Set<number>;
  onToggleProposed: (index: number) => void;
  onEditProposed: (index: number, rule: ProposedRule) => void;
}> = ({ proposedRules, includedProposed, onToggleProposed, onEditProposed }) => {
  Iif (proposedRules.length === 0) {
    return (
      <div className="rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 px-5 py-8 text-center">
        <Shield 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 propose any governance rules for this use case. You can
          add policy and audit rules later from the Rules page.
        </p>
      </div>
    );
  }
 
  return (
    <div className="space-y-4">
      <SectionCard
        icon={Sparkles}
        title="Governance rules to create"
        description="Each rule acts in one layer of a request: whether it may run, what the model reads, or what comes back. All rules are scoped to this agent and can be edited later in the visual rule builder."
      >
        <div className="space-y-2">
          {proposedRules.map((rule, index) => (
            <ToggleRow
              key={index}
              title={rule.name}
              subtitle={`When ${conditionSummary(rule)} → ${actionSummary(rule)}`}
              meta={<>{ruleLayerMeta(rule.layer).label}</>}
              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={rule.name}
                      onChange={(e) =>
                        onEditProposed(index, { ...rule, name: e.target.value })
                      }
                      className={inputBase}
                    />
                  </div>
                  <div>
                    <FieldLabel label="Description" />
                    <textarea
                      value={rule.description}
                      onChange={(e) =>
                        onEditProposed(index, {
                          ...rule,
                          description: e.target.value,
                        })
                      }
                      rows={2}
                      className={inputBase + " resize-none"}
                    />
                  </div>
                </div>
              )}
            </ToggleRow>
          ))}
        </div>
      </SectionCard>
    </div>
  );
};
 
export default ReviewRulesStep;