{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "request-inspector",
  "title": "Request Inspector",
  "description": "Inspect HTTP requests and responses with status codes, headers, timing, format detection, and cURL generation.",
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "badge",
    "button",
    "@drift-ui/json-viewer",
    "@drift-ui/secret-field",
    "@drift-ui/use-controllable-state",
    "@drift-ui/use-copy-to-clipboard",
    "@drift-ui/warning-color"
  ],
  "files": [
    {
      "path": "registry/base/ui/request-inspector.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  CheckIcon,\n  ClockIcon,\n  CopyIcon,\n  TerminalIcon,\n  TextWrapIcon,\n} from \"lucide-react\"\nimport { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\"\n\nimport { useControllableState } from \"@/registry/default/hooks/use-controllable-state\"\nimport { useCopyToClipboard } from \"@/registry/default/hooks/use-copy-to-clipboard\"\nimport {\n  buildCurlCommand,\n  DEFAULT_SENSITIVE_HEADERS,\n  formatDuration,\n  getStatusBadgeClass,\n  getStatusText,\n  isSensitiveHeader,\n  normalizeHeaders,\n  parseBody,\n  parseQueryParams,\n  type HttpMethod,\n  type RequestInspectorHeaders,\n  type RequestInspectorRequest,\n  type RequestInspectorResponse,\n} from \"@/registry/default/lib/request-inspector-utils\"\nimport { cn } from \"@/registry/default/lib/utils\"\nimport { Badge } from \"@/registry/base/ui/badge\"\nimport { Button } from \"@/registry/base/ui/button\"\nimport { JsonViewer } from \"@/registry/default/ui/json-viewer\"\nimport { SecretField } from \"@/registry/default/ui/secret-field\"\n\nexport type {\n  HttpMethod,\n  RequestInspectorHeaders,\n  RequestInspectorRequest,\n  RequestInspectorResponse,\n}\n\nexport interface RequestInspectorProps extends Omit<\n  React.ComponentProps<\"div\">,\n  \"defaultValue\"\n> {\n  request: RequestInspectorRequest\n  response?: RequestInspectorResponse\n  defaultTab?: \"request\" | \"response\" | \"headers\" | \"timing\"\n  tab?: \"request\" | \"response\" | \"headers\" | \"timing\"\n  onTabChange?: (tab: \"request\" | \"response\" | \"headers\" | \"timing\") => void\n  sensitiveHeaders?: string[]\n  hideCurl?: boolean\n}\n\nfunction HeaderList({\n  title,\n  headers,\n  sensitiveHeaders,\n  onCopy,\n  copiedKey,\n}: {\n  title: string\n  headers: [string, string][]\n  sensitiveHeaders: string[]\n  onCopy: (text: string, key: string) => void\n  copiedKey: string | null\n}) {\n  return (\n    <div className=\"flex flex-col gap-2\">\n      <div className=\"flex items-center justify-between\">\n        <span className=\"text-xs font-semibold text-muted-foreground\">\n          {title} ({headers.length})\n        </span>\n      </div>\n      {headers.length === 0 ? (\n        <div className=\"rounded-md border border-dashed p-4 text-center text-xs text-muted-foreground\">\n          No headers\n        </div>\n      ) : (\n        <div className=\"flex flex-col divide-y rounded-md border bg-card\">\n          {headers.map(([name, value], index) => {\n            const isSensitive = isSensitiveHeader(name, sensitiveHeaders)\n            const itemKey = `${title}-${name}-${index}`\n            const isCopied = copiedKey === itemKey\n\n            return (\n              <div\n                key={itemKey}\n                className=\"flex flex-col gap-1.5 p-2.5 sm:flex-row sm:items-center sm:justify-between sm:gap-4\"\n              >\n                <span\n                  className=\"font-mono text-xs font-semibold text-foreground sm:w-44 sm:shrink-0\"\n                  title={name}\n                >\n                  {name}\n                </span>\n                <div className=\"min-w-0 flex-1\">\n                  {isSensitive ? (\n                    <SecretField\n                      aria-label={`${name} header`}\n                      value={value}\n                      className=\"h-7 text-xs\"\n                    />\n                  ) : (\n                    <div className=\"group flex items-center justify-between gap-2 rounded border bg-muted/20 px-2 py-1 font-mono text-xs text-foreground\">\n                      <span className=\"min-w-0 truncate select-all\">\n                        {value}\n                      </span>\n                      <button\n                        type=\"button\"\n                        aria-label={`Copy ${name} header value`}\n                        onClick={() => onCopy(value, itemKey)}\n                        className=\"inline-flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground opacity-60 transition-opacity hover:bg-background hover:text-foreground hover:opacity-100 focus-visible:opacity-100\"\n                      >\n                        {isCopied ? (\n                          <CheckIcon className=\"size-3\" />\n                        ) : (\n                          <CopyIcon className=\"size-3\" />\n                        )}\n                      </button>\n                    </div>\n                  )}\n                </div>\n              </div>\n            )\n          })}\n        </div>\n      )}\n    </div>\n  )\n}\n\nfunction RequestInspector({\n  request,\n  response,\n  defaultTab = \"request\",\n  tab: tabProp,\n  onTabChange,\n  sensitiveHeaders = DEFAULT_SENSITIVE_HEADERS,\n  hideCurl = false,\n  className,\n  ...props\n}: RequestInspectorProps) {\n  const { value: activeTab, setValue: setActiveTab } =\n    useControllableState<string>({\n      value: tabProp,\n      defaultValue: defaultTab,\n      onChange: onTabChange as ((value: string) => void) | undefined,\n    })\n\n  const [wrapRequest, setWrapRequest] = React.useState(false)\n  const [wrapResponse, setWrapResponse] = React.useState(false)\n\n  const { copied, copy } = useCopyToClipboard()\n\n  const queryParams = React.useMemo(\n    () => parseQueryParams(request.url),\n    [request.url]\n  )\n  const requestHeaders = React.useMemo(\n    () => normalizeHeaders(request.headers),\n    [request.headers]\n  )\n  const responseHeaders = React.useMemo(\n    () => normalizeHeaders(response?.headers),\n    [response?.headers]\n  )\n\n  const requestBodyParsed = React.useMemo(\n    () => parseBody(request.body),\n    [request.body]\n  )\n  const responseBodyParsed = React.useMemo(\n    () => parseBody(response?.body),\n    [response?.body]\n  )\n\n  const curlCommand = React.useMemo(() => buildCurlCommand(request), [request])\n\n  const statusVariant = response\n    ? getStatusBadgeClass(response.status)\n    : { className: \"\", label: \"\" }\n  const statusText = response\n    ? response.statusText?.trim() || getStatusText(response.status)\n    : \"\"\n\n  const totalHeadersCount = requestHeaders.length + responseHeaders.length\n\n  return (\n    <div\n      data-slot=\"request-inspector\"\n      className={cn(\n        \"flex flex-col overflow-hidden rounded-lg border bg-card text-card-foreground shadow-sm\",\n        className\n      )}\n      {...props}\n    >\n      {/* Header bar / overview */}\n      <div className=\"flex flex-wrap items-center justify-between gap-3 border-b bg-muted/30 px-3 py-2.5 sm:px-4\">\n        <div className=\"flex min-w-[min(100%,24rem)] flex-1 items-center gap-2\">\n          <Badge\n            variant=\"outline\"\n            className=\"shrink-0 font-mono text-xs font-semibold tracking-wider uppercase\"\n          >\n            {request.method}\n          </Badge>\n          <span\n            className=\"min-w-0 flex-1 truncate font-mono text-xs text-foreground select-all\"\n            title={request.url}\n          >\n            {request.url}\n          </span>\n          <button\n            type=\"button\"\n            aria-label=\"Copy URL\"\n            onClick={() => copy(request.url, \"url\")}\n            className=\"inline-flex size-6 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground\"\n          >\n            {copied === \"url\" ? (\n              <CheckIcon className=\"size-3.5\" />\n            ) : (\n              <CopyIcon className=\"size-3.5\" />\n            )}\n          </button>\n        </div>\n\n        <div className=\"flex items-center gap-2\">\n          {response && (\n            <>\n              <Badge\n                className={cn(\n                  \"shrink-0 border font-mono text-xs font-medium\",\n                  statusVariant.className\n                )}\n              >\n                {response.status} {statusText}\n              </Badge>\n              {response.durationMs !== undefined && (\n                <span className=\"hidden items-center gap-1 font-mono text-xs text-muted-foreground sm:inline-flex\">\n                  <ClockIcon className=\"size-3\" />\n                  {formatDuration(response.durationMs)}\n                </span>\n              )}\n            </>\n          )}\n\n          {!hideCurl && (\n            <Button\n              type=\"button\"\n              variant=\"outline\"\n              size=\"sm\"\n              onClick={() => copy(curlCommand, \"curl\")}\n              className=\"h-7 gap-1.5 px-2 text-xs\"\n              aria-label=\"Copy as cURL\"\n            >\n              {copied === \"curl\" ? (\n                <CheckIcon className=\"size-3.5\" />\n              ) : (\n                <TerminalIcon className=\"size-3.5\" />\n              )}\n              <span className=\"hidden sm:inline\">\n                {copied === \"curl\" ? \"Copied\" : \"Copy as cURL\"}\n              </span>\n            </Button>\n          )}\n        </div>\n      </div>\n\n      {/* Tabs navigation & panels */}\n      <TabsPrimitive.Root\n        value={activeTab}\n        onValueChange={(val) => setActiveTab(String(val))}\n        className=\"flex flex-col\"\n      >\n        <TabsPrimitive.List\n          aria-label=\"Request and response details\"\n          className=\"flex gap-1 overflow-x-auto border-b border-border bg-muted/20 px-3 pt-2\"\n        >\n          <TabsPrimitive.Tab\n            value=\"request\"\n            className=\"inline-flex items-center gap-1.5 rounded-t-sm border-b-2 border-transparent px-3 py-1.5 text-xs font-medium text-muted-foreground transition-all outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[selected]:border-primary data-[selected]:text-foreground\"\n          >\n            <span>Request</span>\n            {requestBodyParsed.text ? (\n              <span className=\"py-0.2 rounded bg-muted px-1 text-[10px] text-muted-foreground\">\n                {requestBodyParsed.isJson ? \"JSON\" : \"Body\"}\n              </span>\n            ) : null}\n          </TabsPrimitive.Tab>\n\n          <TabsPrimitive.Tab\n            value=\"response\"\n            className=\"inline-flex items-center gap-1.5 rounded-t-sm border-b-2 border-transparent px-3 py-1.5 text-xs font-medium text-muted-foreground transition-all outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[selected]:border-primary data-[selected]:text-foreground\"\n          >\n            <span>Response</span>\n            {response ? (\n              <span\n                className={cn(\n                  \"py-0.2 rounded border px-1 font-mono text-[10px]\",\n                  statusVariant.className\n                )}\n              >\n                {response.status}\n              </span>\n            ) : null}\n          </TabsPrimitive.Tab>\n\n          <TabsPrimitive.Tab\n            value=\"headers\"\n            className=\"inline-flex items-center gap-1.5 rounded-t-sm border-b-2 border-transparent px-3 py-1.5 text-xs font-medium text-muted-foreground transition-all outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[selected]:border-primary data-[selected]:text-foreground\"\n          >\n            <span>Headers</span>\n            {totalHeadersCount > 0 && (\n              <span className=\"py-0.2 rounded bg-muted px-1.5 text-[10px] text-muted-foreground\">\n                {totalHeadersCount}\n              </span>\n            )}\n          </TabsPrimitive.Tab>\n\n          <TabsPrimitive.Tab\n            value=\"timing\"\n            className=\"inline-flex items-center gap-1.5 rounded-t-sm border-b-2 border-transparent px-3 py-1.5 text-xs font-medium text-muted-foreground transition-all outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring data-[selected]:border-primary data-[selected]:text-foreground\"\n          >\n            <span>Timing</span>\n            {response?.durationMs !== undefined && (\n              <span className=\"font-mono text-[10px] text-muted-foreground\">\n                {formatDuration(response.durationMs)}\n              </span>\n            )}\n          </TabsPrimitive.Tab>\n        </TabsPrimitive.List>\n\n        {/* Tab 1: Request */}\n        <TabsPrimitive.Panel\n          value=\"request\"\n          className=\"flex flex-col gap-4 p-4 outline-none\"\n        >\n          {queryParams.length > 0 && (\n            <div className=\"flex flex-col gap-2\">\n              <span className=\"text-xs font-semibold text-muted-foreground\">\n                Query Parameters ({queryParams.length})\n              </span>\n              <div className=\"flex flex-col divide-y rounded-md border bg-card\">\n                {queryParams.map(([key, val], index) => (\n                  <div\n                    key={`${key}-${index}`}\n                    className=\"flex items-center justify-between px-3 py-1.5 font-mono text-xs\"\n                  >\n                    <span className=\"font-medium text-foreground\">{key}</span>\n                    <span className=\"text-muted-foreground select-all\">\n                      {val}\n                    </span>\n                  </div>\n                ))}\n              </div>\n            </div>\n          )}\n\n          <div className=\"flex flex-col gap-2\">\n            <div className=\"flex items-center justify-between\">\n              <span className=\"text-xs font-semibold text-muted-foreground\">\n                Request Body\n              </span>\n              {requestBodyParsed.text && (\n                <div className=\"flex items-center gap-1\">\n                  {!requestBodyParsed.isJson && (\n                    <Button\n                      type=\"button\"\n                      size=\"sm\"\n                      variant={wrapRequest ? \"secondary\" : \"ghost\"}\n                      aria-pressed={wrapRequest}\n                      onClick={() => setWrapRequest(!wrapRequest)}\n                      className=\"h-6 gap-1 px-2 text-xs\"\n                    >\n                      <TextWrapIcon className=\"size-3\" />\n                      Wrap\n                    </Button>\n                  )}\n                  <Button\n                    type=\"button\"\n                    size=\"sm\"\n                    variant=\"ghost\"\n                    onClick={() => copy(requestBodyParsed.text, \"req-body\")}\n                    className=\"h-6 gap-1 px-2 text-xs\"\n                    aria-label=\"Copy request body\"\n                  >\n                    {copied === \"req-body\" ? (\n                      <CheckIcon className=\"size-3\" />\n                    ) : (\n                      <CopyIcon className=\"size-3\" />\n                    )}\n                    {copied === \"req-body\" ? \"Copied\" : \"Copy\"}\n                  </Button>\n                </div>\n              )}\n            </div>\n\n            {!requestBodyParsed.text ? (\n              <div className=\"rounded-md border border-dashed py-8 text-center text-xs text-muted-foreground\">\n                No request body\n              </div>\n            ) : requestBodyParsed.isJson ? (\n              <JsonViewer\n                data={requestBodyParsed.jsonValue}\n                defaultExpandDepth={2}\n                aria-label=\"Request JSON body\"\n                className=\"rounded-md border bg-muted/10 p-2\"\n              />\n            ) : (\n              <pre\n                className={cn(\n                  \"max-h-80 overflow-auto rounded-md border bg-muted/20 p-3 font-mono text-xs\",\n                  wrapRequest\n                    ? \"break-all whitespace-pre-wrap\"\n                    : \"whitespace-pre\"\n                )}\n              >\n                <code>{requestBodyParsed.text}</code>\n              </pre>\n            )}\n          </div>\n        </TabsPrimitive.Panel>\n\n        {/* Tab 2: Response */}\n        <TabsPrimitive.Panel\n          value=\"response\"\n          className=\"flex flex-col gap-4 p-4 outline-none\"\n        >\n          {!response ? (\n            <div className=\"rounded-md border border-dashed py-10 text-center text-xs text-muted-foreground\">\n              No response recorded\n            </div>\n          ) : (\n            <>\n              <div className=\"flex flex-wrap items-center gap-3 rounded-md border bg-muted/20 p-3 text-xs\">\n                <div className=\"flex items-center gap-1.5 font-mono\">\n                  <span className=\"text-muted-foreground\">Status:</span>\n                  <Badge\n                    className={cn(\n                      \"border font-mono text-xs font-medium\",\n                      statusVariant.className\n                    )}\n                  >\n                    {response.status} {statusText}\n                  </Badge>\n                </div>\n                {response.durationMs !== undefined && (\n                  <div className=\"flex items-center gap-1.5 font-mono\">\n                    <span className=\"text-muted-foreground\">Duration:</span>\n                    <span className=\"font-semibold text-foreground\">\n                      {formatDuration(response.durationMs)}\n                    </span>\n                  </div>\n                )}\n              </div>\n\n              <div className=\"flex flex-col gap-2\">\n                <div className=\"flex items-center justify-between\">\n                  <span className=\"text-xs font-semibold text-muted-foreground\">\n                    Response Body\n                  </span>\n                  {responseBodyParsed.text && (\n                    <div className=\"flex items-center gap-1\">\n                      {!responseBodyParsed.isJson && (\n                        <Button\n                          type=\"button\"\n                          size=\"sm\"\n                          variant={wrapResponse ? \"secondary\" : \"ghost\"}\n                          aria-pressed={wrapResponse}\n                          onClick={() => setWrapResponse(!wrapResponse)}\n                          className=\"h-6 gap-1 px-2 text-xs\"\n                        >\n                          <TextWrapIcon className=\"size-3\" />\n                          Wrap\n                        </Button>\n                      )}\n                      <Button\n                        type=\"button\"\n                        size=\"sm\"\n                        variant=\"ghost\"\n                        onClick={() =>\n                          copy(responseBodyParsed.text, \"res-body\")\n                        }\n                        className=\"h-6 gap-1 px-2 text-xs\"\n                        aria-label=\"Copy response body\"\n                      >\n                        {copied === \"res-body\" ? (\n                          <CheckIcon className=\"size-3\" />\n                        ) : (\n                          <CopyIcon className=\"size-3\" />\n                        )}\n                        {copied === \"res-body\" ? \"Copied\" : \"Copy\"}\n                      </Button>\n                    </div>\n                  )}\n                </div>\n\n                {!responseBodyParsed.text ? (\n                  <div className=\"rounded-md border border-dashed py-8 text-center text-xs text-muted-foreground\">\n                    No response body\n                  </div>\n                ) : responseBodyParsed.isJson ? (\n                  <JsonViewer\n                    data={responseBodyParsed.jsonValue}\n                    defaultExpandDepth={2}\n                    aria-label=\"Response JSON body\"\n                    className=\"rounded-md border bg-muted/10 p-2\"\n                  />\n                ) : (\n                  <pre\n                    className={cn(\n                      \"max-h-80 overflow-auto rounded-md border bg-muted/20 p-3 font-mono text-xs\",\n                      wrapResponse\n                        ? \"break-all whitespace-pre-wrap\"\n                        : \"whitespace-pre\"\n                    )}\n                  >\n                    <code>{responseBodyParsed.text}</code>\n                  </pre>\n                )}\n              </div>\n            </>\n          )}\n        </TabsPrimitive.Panel>\n\n        {/* Tab 3: Headers */}\n        <TabsPrimitive.Panel\n          value=\"headers\"\n          className=\"flex flex-col gap-6 p-4 outline-none\"\n        >\n          <HeaderList\n            title=\"Request Headers\"\n            headers={requestHeaders}\n            sensitiveHeaders={sensitiveHeaders}\n            onCopy={copy}\n            copiedKey={copied}\n          />\n          <HeaderList\n            title=\"Response Headers\"\n            headers={responseHeaders}\n            sensitiveHeaders={sensitiveHeaders}\n            onCopy={copy}\n            copiedKey={copied}\n          />\n        </TabsPrimitive.Panel>\n\n        {/* Tab 4: Timing */}\n        <TabsPrimitive.Panel\n          value=\"timing\"\n          className=\"flex flex-col gap-4 p-4 outline-none\"\n        >\n          <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-3\">\n            <div className=\"flex flex-col gap-1 rounded-md border bg-card p-3\">\n              <span className=\"text-xs text-muted-foreground\">Duration</span>\n              <span className=\"font-mono text-base font-semibold text-foreground\">\n                {formatDuration(response?.durationMs)}\n              </span>\n            </div>\n            <div className=\"flex flex-col gap-1 rounded-md border bg-card p-3\">\n              <span className=\"text-xs text-muted-foreground\">Status</span>\n              <span className=\"font-mono text-base font-semibold text-foreground\">\n                {response ? `${response.status} ${statusText}` : \"—\"}\n              </span>\n            </div>\n            <div className=\"flex flex-col gap-1 rounded-md border bg-card p-3\">\n              <span className=\"text-xs text-muted-foreground\">Headers</span>\n              <span className=\"font-mono text-base font-semibold text-foreground\">\n                {requestHeaders.length} req / {responseHeaders.length} res\n              </span>\n            </div>\n          </div>\n\n          {response?.durationMs !== undefined && (\n            <div className=\"flex flex-col gap-1.5 rounded-md border bg-muted/10 p-3\">\n              <div className=\"flex items-center justify-between font-mono text-xs\">\n                <span className=\"text-muted-foreground\">Roundtrip Latency</span>\n                <span\n                  className={cn(\n                    \"font-medium\",\n                    response.durationMs < 200\n                      ? \"text-chart-2\"\n                      : response.durationMs < 1000\n                        ? \"text-chart-4\"\n                        : \"text-warning\"\n                  )}\n                >\n                  {response.durationMs < 200\n                    ? \"Fast\"\n                    : response.durationMs < 1000\n                      ? \"Normal\"\n                      : \"Slow\"}\n                </span>\n              </div>\n              <div className=\"h-2 w-full overflow-hidden rounded-full bg-muted\">\n                <div\n                  className={cn(\n                    \"h-full rounded-full transition-all\",\n                    response.durationMs < 200\n                      ? \"bg-chart-2\"\n                      : response.durationMs < 1000\n                        ? \"bg-chart-4\"\n                        : \"bg-warning\"\n                  )}\n                  style={{\n                    width: `${Math.min(100, Math.max(5, (response.durationMs / 1000) * 100))}%`,\n                  }}\n                />\n              </div>\n            </div>\n          )}\n        </TabsPrimitive.Panel>\n      </TabsPrimitive.Root>\n\n      {/* Screen reader notification for copy actions */}\n      <span role=\"status\" className=\"sr-only\">\n        {copied ? \"Copied to clipboard\" : \"\"}\n      </span>\n    </div>\n  )\n}\n\nexport { RequestInspector }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/default/lib/request-inspector-utils.ts",
      "content": "export interface RequestInspectorHeaders {\n  [key: string]: string | string[] | undefined\n}\n\nexport type HttpMethod =\n  | \"GET\"\n  | \"POST\"\n  | \"PUT\"\n  | \"PATCH\"\n  | \"DELETE\"\n  | \"HEAD\"\n  | \"OPTIONS\"\n  | (string & {})\n\nexport interface RequestInspectorRequest {\n  method: HttpMethod\n  url: string\n  headers?: RequestInspectorHeaders | [string, string][]\n  body?: unknown\n}\n\nexport interface RequestInspectorResponse {\n  status: number\n  statusText?: string\n  headers?: RequestInspectorHeaders | [string, string][]\n  body?: unknown\n  durationMs?: number\n}\n\nexport const DEFAULT_SENSITIVE_HEADERS = [\n  \"authorization\",\n  \"cookie\",\n  \"set-cookie\",\n  \"x-api-key\",\n  \"api-key\",\n  \"proxy-authorization\",\n  \"x-auth-token\",\n  \"x-access-token\",\n]\n\nconst STATUS_TEXT_MAP: Record<number, string> = {\n  100: \"Continue\",\n  101: \"Switching Protocols\",\n  102: \"Processing\",\n  103: \"Early Hints\",\n  200: \"OK\",\n  201: \"Created\",\n  202: \"Accepted\",\n  203: \"Non-Authoritative Information\",\n  204: \"No Content\",\n  205: \"Reset Content\",\n  206: \"Partial Content\",\n  207: \"Multi-Status\",\n  208: \"Already Reported\",\n  226: \"IM Used\",\n  300: \"Multiple Choices\",\n  301: \"Moved Permanently\",\n  302: \"Found\",\n  303: \"See Other\",\n  304: \"Not Modified\",\n  305: \"Use Proxy\",\n  307: \"Temporary Redirect\",\n  308: \"Permanent Redirect\",\n  400: \"Bad Request\",\n  401: \"Unauthorized\",\n  402: \"Payment Required\",\n  403: \"Forbidden\",\n  404: \"Not Found\",\n  405: \"Method Not Allowed\",\n  406: \"Not Acceptable\",\n  407: \"Proxy Authentication Required\",\n  408: \"Request Timeout\",\n  409: \"Conflict\",\n  410: \"Gone\",\n  411: \"Length Required\",\n  412: \"Precondition Failed\",\n  413: \"Payload Too Large\",\n  414: \"URI Too Long\",\n  415: \"Unsupported Media Type\",\n  416: \"Range Not Satisfiable\",\n  417: \"Expectation Failed\",\n  418: \"I'm a teapot\",\n  421: \"Misdirected Request\",\n  422: \"Unprocessable Entity\",\n  423: \"Locked\",\n  424: \"Failed Dependency\",\n  425: \"Too Early\",\n  426: \"Upgrade Required\",\n  428: \"Precondition Required\",\n  429: \"Too Many Requests\",\n  431: \"Request Header Fields Too Large\",\n  451: \"Unavailable For Legal Reasons\",\n  500: \"Internal Server Error\",\n  501: \"Not Implemented\",\n  502: \"Bad Gateway\",\n  503: \"Service Unavailable\",\n  504: \"Gateway Timeout\",\n  505: \"HTTP Version Not Supported\",\n  506: \"Variant Also Negotiates\",\n  507: \"Insufficient Storage\",\n  508: \"Loop Detected\",\n  510: \"Not Extended\",\n  511: \"Network Authentication Required\",\n}\n\nexport function quoteShell(arg: string): string {\n  return `'${arg.replace(/'/g, \"'\\\\''\")}'`\n}\n\nexport function isSensitiveHeader(\n  name: string,\n  sensitiveHeaders: string[] = DEFAULT_SENSITIVE_HEADERS\n): boolean {\n  const lower = name.trim().toLowerCase()\n  return sensitiveHeaders.some(\n    (header) => header.trim().toLowerCase() === lower\n  )\n}\n\nexport function normalizeHeaders(\n  headers?: RequestInspectorHeaders | [string, string][]\n): [string, string][] {\n  if (!headers) return []\n  if (Array.isArray(headers)) return headers\n\n  const entries: [string, string][] = []\n  for (const [key, value] of Object.entries(headers)) {\n    if (value === undefined) continue\n    if (Array.isArray(value)) {\n      for (const item of value) {\n        entries.push([key, item])\n      }\n    } else {\n      entries.push([key, String(value)])\n    }\n  }\n  return entries\n}\n\nexport function parseQueryParams(url: string): [string, string][] {\n  if (!url) return []\n  try {\n    const parsed = new URL(url, \"https://drift-ui.dev\")\n    const entries: [string, string][] = []\n    parsed.searchParams.forEach((value, key) => {\n      entries.push([key, value])\n    })\n    return entries\n  } catch {\n    return []\n  }\n}\n\nexport function parseBody(body: unknown): {\n  isJson: boolean\n  jsonValue?: unknown\n  text: string\n} {\n  if (body === undefined || body === null) {\n    return { isJson: false, text: \"\" }\n  }\n\n  if (typeof body === \"object\") {\n    try {\n      const jsonText = JSON.stringify(body, null, 2)\n      return {\n        isJson: true,\n        jsonValue: body,\n        text: jsonText,\n      }\n    } catch {\n      return { isJson: false, text: String(body) }\n    }\n  }\n\n  if (typeof body === \"string\") {\n    const trimmed = body.trim()\n    try {\n      const parsed = JSON.parse(trimmed)\n      if (typeof parsed === \"object\" && parsed !== null) {\n        return {\n          isJson: true,\n          jsonValue: parsed,\n          text: body,\n        }\n      }\n    } catch {\n      // not valid object/array JSON\n    }\n    return { isJson: false, text: body }\n  }\n\n  return { isJson: false, text: String(body) }\n}\n\nexport function formatDuration(ms?: number): string {\n  if (ms === undefined || ms === null || !Number.isFinite(ms) || ms < 0) {\n    return \"—\"\n  }\n  if (ms === 0) {\n    return \"0 ms\"\n  }\n  if (ms < 1) {\n    return \"< 1 ms\"\n  }\n  const roundedMs = Number.isInteger(ms) ? ms : Number(ms.toFixed(1))\n  if (roundedMs < 1000) {\n    return `${roundedMs} ms`\n  }\n  const sec = Number((ms / 1000).toFixed(2))\n  return `${sec} s`\n}\n\nexport function getStatusText(status: number): string {\n  return STATUS_TEXT_MAP[status] ?? \"Unknown\"\n}\n\nexport function getStatusBadgeClass(status: number): {\n  className: string\n  label: string\n} {\n  if (status >= 100 && status < 200) {\n    return {\n      className: \"border-border bg-muted text-muted-foreground\",\n      label: \"Informational\",\n    }\n  }\n  if (status >= 200 && status < 300) {\n    return {\n      className: \"border-chart-2/30 bg-chart-2/15 text-chart-2\",\n      label: \"Success\",\n    }\n  }\n  if (status >= 300 && status < 400) {\n    return {\n      className: \"border-chart-4/30 bg-chart-4/15 text-chart-4\",\n      label: \"Redirection\",\n    }\n  }\n  if (status >= 400 && status < 500) {\n    return {\n      className: \"border-warning/30 bg-warning/15 text-warning\",\n      label: \"Client error\",\n    }\n  }\n  if (status >= 500 && status < 600) {\n    return {\n      className: \"border-destructive/30 bg-destructive/15 text-destructive\",\n      label: \"Server error\",\n    }\n  }\n  return {\n    className: \"border-border bg-muted text-muted-foreground\",\n    label: \"Unknown\",\n  }\n}\n\nexport function buildCurlCommand(\n  request: RequestInspectorRequest,\n  options?: {\n    maskSensitive?: boolean\n    sensitiveHeaders?: string[]\n  }\n): string {\n  const parts: string[] = [\"curl\"]\n  const rawMethod = request.method?.trim() || \"GET\"\n  const upperMethod = rawMethod.toUpperCase()\n\n  parts.push(quoteShell(request.url))\n\n  const hasBody =\n    request.body !== undefined && request.body !== null && request.body !== \"\"\n\n  if (upperMethod === \"HEAD\") {\n    parts.push(\"-I\")\n  } else if (upperMethod !== \"GET\" || hasBody) {\n    parts.push(`-X ${quoteShell(rawMethod)}`)\n  }\n\n  const mask = options?.maskSensitive ?? false\n  const sensitiveList = options?.sensitiveHeaders ?? DEFAULT_SENSITIVE_HEADERS\n  const headers = normalizeHeaders(request.headers)\n  for (const [key, value] of headers) {\n    const val =\n      mask && isSensitiveHeader(key, sensitiveList) ? \"[REDACTED]\" : value\n    parts.push(`-H ${quoteShell(`${key}: ${val}`)}`)\n  }\n\n  if (hasBody) {\n    let bodyString = \"\"\n    if (typeof request.body === \"string\") {\n      bodyString = request.body\n    } else {\n      try {\n        bodyString = JSON.stringify(request.body, null, 2)\n      } catch {\n        bodyString = String(request.body)\n      }\n    }\n    parts.push(`--data-raw ${quoteShell(bodyString)}`)\n  }\n\n  if (parts.length <= 2) {\n    return parts.join(\" \")\n  }\n\n  return parts[0] + \" \" + parts.slice(1).join(\" \\\\\\n  \")\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:ui"
}