{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "elements-elicitation-form",
  "type": "registry:component",
  "title": "Elicitation form",
  "description": "A server pausing mid-tool-call to ask you for the fields it still needs.",
  "registryDependencies": [
    "https://r.assistant-ui.com/base/elements-surfaces.json",
    "https://r.assistant-ui.com/base/elements-receipt-focus.json"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "type": "registry:component",
      "path": "components/assistant-ui/elements/elicitation-form.tsx",
      "sourcePath": "packages/ui/src/components/react/assistant-ui/elements/elicitation-form.tsx",
      "content": "\"use client\";\n\nimport { useId, type ComponentProps } from \"react\";\nimport { CheckIcon, PlugIcon, XIcon } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { field, inkButton, mono, paper } from \"./surfaces\";\nimport { useReceiptFocus } from \"./receipt-focus\";\n\nexport type ElicitationState = \"request\" | \"accepted\" | \"declined\";\n\nexport interface ElicitationField {\n  name: string;\n  label: string;\n  value: string;\n  kind: \"text\" | \"choice\" | \"toggle\";\n  options?: readonly string[];\n  required?: boolean;\n}\n\nfunction Toggle({ value }: { value: string }) {\n  const enabled = value === \"true\";\n  return (\n    <>\n      <span\n        aria-hidden\n        className={cn(\n          \"flex h-4 w-7 items-center rounded-full p-0.5 transition-colors duration-200\",\n          enabled ? \"bg-foreground/80\" : \"bg-foreground/15\",\n        )}\n      >\n        <span\n          className={cn(\n            \"bg-background size-3 rounded-full transition-transform duration-200 motion-reduce:transition-none\",\n            enabled && \"translate-x-3\",\n          )}\n        />\n      </span>\n      <span className=\"text-muted-foreground text-xs\">\n        {enabled ? \"On\" : \"Off\"}\n      </span>\n    </>\n  );\n}\n\nexport function ElicitationForm({\n  server,\n  message,\n  fields,\n  state,\n  onFieldChange,\n  onAccept,\n  onDecline,\n  className,\n  ...props\n}: Omit<\n  ComponentProps<\"div\">,\n  | \"children\"\n  | \"server\"\n  | \"message\"\n  | \"fields\"\n  | \"state\"\n  | \"onFieldChange\"\n  | \"onAccept\"\n  | \"onDecline\"\n> & {\n  server: string;\n  message: string;\n  fields: readonly ElicitationField[];\n  state: ElicitationState;\n  onFieldChange?: ((name: string, value: string) => void) | undefined;\n  onAccept?: () => void;\n  onDecline?: () => void;\n}) {\n  const fieldPrefix = useId();\n  const { receiptRef, focusHandlers } = useReceiptFocus(props);\n  const interactive = state === \"request\" && onFieldChange !== undefined;\n  const missingRequired =\n    interactive &&\n    fields.some(\n      (item) =>\n        item.kind !== \"toggle\" &&\n        item.required === true &&\n        item.value.trim() === \"\",\n    );\n\n  return (\n    <div\n      data-slot=\"elicitation-form\"\n      className={cn(\n        paper,\n        \"flex w-full max-w-sm flex-col gap-3.5 rounded-[20px] p-4\",\n        className,\n      )}\n\n      {...props}\n      {...focusHandlers}\n    >\n      <div className=\"flex items-center gap-2.5\">\n        <span className=\"bg-foreground/[0.05] text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded-lg\">\n          <PlugIcon className=\"size-3.5\" />\n        </span>\n        <span className=\"min-w-0 flex-1 truncate text-[13.5px] font-medium\">\n          {server}\n        </span>\n        <span className={cn(mono, \"text-muted-foreground shrink-0\")}>\n          needs input\n        </span>\n      </div>\n\n      <p className=\"text-muted-foreground text-xs leading-relaxed\">{message}</p>\n\n      <div className=\"flex flex-col gap-2.5\">\n        {fields.map((item, index) => {\n          const labelId = `${fieldPrefix}-${index}`;\n          const inputId = `${labelId}-input`;\n          return (\n            <div key={item.name} className=\"flex flex-col gap-1\">\n              {item.kind === \"text\" && interactive ? (\n                <label\n                  id={labelId}\n                  htmlFor={inputId}\n                  className={cn(mono, \"text-muted-foreground\")}\n                >\n                  {item.label}\n                  {item.required && (\n                    <span className=\"text-muted-foreground\"> *</span>\n                  )}\n                </label>\n              ) : (\n                <span\n                  id={labelId}\n                  className={cn(mono, \"text-muted-foreground\")}\n                >\n                  {item.label}\n                  {item.required && (\n                    <span className=\"text-muted-foreground\"> *</span>\n                  )}\n                </span>\n              )}\n              {item.kind === \"choice\" ? (\n                <div\n                  role={interactive ? \"group\" : undefined}\n                  aria-labelledby={interactive ? labelId : undefined}\n                  className=\"flex flex-wrap gap-1.5\"\n                >\n                  {item.options?.map((option) =>\n                    interactive ? (\n                      <button\n                        key={option}\n                        type=\"button\"\n                        aria-pressed={option === item.value}\n                        onClick={() => onFieldChange(item.name, option)}\n                        className={cn(\n                          \"focus-visible:ring-foreground/20 rounded-full px-2.5 py-1 text-xs transition-colors outline-none focus-visible:ring-1\",\n                          option === item.value\n                            ? \"bg-foreground text-background\"\n                            : cn(field, \"text-muted-foreground\"),\n                        )}\n                      >\n                        {option}\n                      </button>\n                    ) : (\n                      <span\n                        key={option}\n                        className={cn(\n                          \"rounded-full px-2.5 py-1 text-xs transition-colors\",\n                          option === item.value\n                            ? \"bg-foreground text-background\"\n                            : cn(field, \"text-muted-foreground\"),\n                        )}\n                      >\n                        {option}\n                      </span>\n                    ),\n                  )}\n                </div>\n              ) : item.kind === \"toggle\" ? (\n                interactive ? (\n                  <button\n                    type=\"button\"\n                    role=\"switch\"\n                    aria-labelledby={labelId}\n                    aria-checked={item.value === \"true\"}\n                    onClick={() =>\n                      onFieldChange(\n                        item.name,\n                        item.value === \"true\" ? \"false\" : \"true\",\n                      )\n                    }\n                    className=\"focus-visible:ring-foreground/20 flex w-fit items-center gap-2 rounded-lg outline-none focus-visible:ring-1\"\n                  >\n                    <Toggle value={item.value} />\n                  </button>\n                ) : (\n                  <span className=\"flex items-center gap-2\">\n                    <Toggle value={item.value} />\n                  </span>\n                )\n              ) : interactive ? (\n                <input\n                  id={inputId}\n                  value={item.value}\n                  aria-required={item.required || undefined}\n                  onChange={(event) =>\n                    onFieldChange(item.name, event.currentTarget.value)\n                  }\n                  className={cn(\n                    field,\n                    \"text-foreground/80 focus-visible:ring-foreground/20 rounded-lg px-2.5 py-1.5 text-xs outline-none focus-visible:ring-1\",\n                  )}\n                />\n              ) : (\n                <span\n                  className={cn(\n                    field,\n                    \"text-foreground/80 rounded-lg px-2.5 py-1.5 text-xs\",\n                  )}\n                >\n                  {item.value}\n                </span>\n              )}\n            </div>\n          );\n        })}\n      </div>\n\n      <div className=\"flex h-8 items-center justify-end gap-2\">\n        {state === \"request\" ? (\n          <>\n            <button\n              type=\"button\"\n              onClick={onDecline}\n              className=\"text-muted-foreground hover:bg-foreground/[0.06] hover:text-foreground/90 h-8 rounded-full px-3.5 text-xs font-medium transition-[background-color,color,scale] duration-150 active:scale-[0.96]\"\n            >\n              Decline\n            </button>\n            <button\n              type=\"button\"\n              onClick={onAccept}\n              disabled={missingRequired}\n              className={cn(\n                inkButton,\n                \"flex h-8 items-center rounded-full px-3.5 text-xs font-medium disabled:pointer-events-none disabled:opacity-40\",\n              )}\n            >\n              Send\n            </button>\n          </>\n        ) : (\n          <span\n            key={state}\n            ref={receiptRef}\n            tabIndex={-1}\n            className=\"fade-in animate-in text-muted-foreground flex items-center gap-2 text-xs duration-300\"\n          >\n            {state === \"accepted\" ? (\n              <>\n                <CheckIcon className=\"size-3.5 text-emerald-500\" />\n                Sent to {server}\n              </>\n            ) : (\n              <>\n                <XIcon className=\"text-muted-foreground size-3.5\" />\n                Declined\n              </>\n            )}\n          </span>\n        )}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}