refusal.tsx
This file
Path
apps/web/src/features/shared/refusal.tsx
70 lines · 2.1 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071/** * The words are `@repo/protocol/render`'s; this view only sets them. Whether * retrying can help picks the mark, never the words. */import type { Refusal } from "@repo/protocol/refusal";import { explain, headline } from "@repo/protocol/render";import type { Array } from "effect";import { OctagonX, RotateCcw } from "lucide-react";
import { CommandLine } from "./command.tsx";
const Lines = ({ refusal }: { readonly refusal: Refusal }) => { const prefix = `${refusal._tag}:`;
return ( <samp className="text-mono leading-terminal block max-w-[96ch] font-mono [overflow-wrap:anywhere] whitespace-pre-wrap"> {explain([refusal]).map((line) => ( <span className="block" key={line}> {line.startsWith(prefix) ? ( <> <b className="text-refused font-semibold">{prefix}</b> {line.slice(prefix.length)} </> ) : ( line )} </span> ))} </samp> );};
export const RefusalView = ({ refusals,}: { readonly refusals: Array.NonEmptyReadonlyArray<Refusal>;}) => ( <section aria-label={`Refused: ${headline(refusals)}`} className="border-rule border-y" > <h2 className="text-refused flex items-center gap-2 py-2 font-mono text-sm font-semibold"> <OctagonX aria-hidden="true" className="size-4 shrink-0" /> {headline(refusals)} </h2> <ol className="flex flex-col"> {refusals.map((refusal) => { const Mark = refusal.retryable ? RotateCcw : OctagonX;
return ( <li className="border-rule flex flex-col gap-2 border-t py-3" data-refusal={refusal._tag} data-retryable={refusal.retryable} key={explain([refusal]).join("\n")} > <div className="flex items-start gap-2"> <Mark aria-hidden="true" className={`mt-1 size-3.5 shrink-0 ${refusal.retryable ? "text-waiting" : "text-refused"}`} /> <Lines refusal={refusal} /> </div> <CommandLine command={refusal.next} /> </li> ); })} </ol> </section>);