{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-list",
  "title": "Thread List",
  "description": "Threads grouped by date, or runs by Needs you, Running and Done, with one menu to rename, pin, share, archive and delete.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-menu",
    "@kind-ui/internal-alert-dialog"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/thread-list.tsx",
      "content": "\"use client\";\n\nimport {\n  type ThreadListGridState,\n  type ThreadListLinkState,\n  type ThreadListMenuContentState,\n  type ThreadListSummaryState,\n  type ThreadListTimeState,\n  threadListPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport { type ComponentProps, Fragment, memo, type ReactNode } from \"react\";\nimport {\n  KindAlertDialog,\n  KindAlertDialogBackdrop,\n  KindAlertDialogContent,\n  KindAlertDialogDescription,\n  KindAlertDialogTitle,\n} from \"./internal/alert-dialog\";\nimport { KindMenu, KindMenuContent, KindMenuItem } from \"./internal/menu\";\n\nconst parts = createParts(threadListPrimitive, {\n  root: \"nav\",\n  new: \"button\",\n  viewport: \"div\",\n  grid: \"div\",\n  heading: \"div\",\n  \"heading-cell\": \"div\",\n  row: \"div\",\n  \"link-cell\": \"div\",\n  link: \"a\",\n  status: \"span\",\n  unread: \"span\",\n  summary: \"span\",\n  time: \"span\",\n  editor: \"input\",\n  \"more-cell\": \"div\",\n  more: \"button\",\n  unarchive: \"button\",\n  \"fold-row\": \"div\",\n  \"fold-cell\": \"div\",\n  fold: \"button\",\n  empty: \"p\",\n  menu: \"div\",\n  \"menu-content\": \"div\",\n  dialog: \"div\",\n  \"dialog-error\": \"span\",\n  \"dialog-cancel\": \"button\",\n  \"dialog-delete\": \"button\",\n  end: \"div\",\n  retry: \"button\",\n});\n\nexport type ThreadListProps = ComponentProps<typeof parts.Root>;\n\n/**\n * The threads as a navigation grid, grouped by pinned, the host's groups and date, or by what each run needs from the\n * person with `groupBy=\"status\"`, with New chat above and one menu of Rename, Pin, Share, Archive and Delete for every\n * row. Any `children` replace the default parts.\n */\nexport function ThreadList({ children = DEFAULT_PARTS, ...props }: ThreadListProps) {\n  return <parts.Root {...props}>{children}</parts.Root>;\n}\n\nexport type ThreadListNewProps = ComponentProps<typeof parts.New>;\n\n/** Calls `onNew`. Reads \"New chat\" unless you pass children. Rendered only while `onNew` is set. */\nexport function ThreadListNew({ children = NEW_CHAT, ...props }: ThreadListNewProps) {\n  return <parts.New {...props}>{children}</parts.New>;\n}\n\nexport type ThreadListEmptyProps = ComponentProps<typeof parts.Empty>;\n\n/** \"Nothing is waiting on you.\" when grouped by status with nothing waiting or running, unless you pass children. */\nexport function ThreadListEmpty({ children = EMPTY, ...props }: ThreadListEmptyProps) {\n  return <parts.Empty {...props}>{children}</parts.Empty>;\n}\n\nconst EMPTY = ({ text }: { text: string }) => text;\n\n/** Scrolls the rows, of which it renders only those in view. Holds a `ThreadListGrid` and a `ThreadListEnd`. */\nexport const ThreadListViewport = parts.Viewport;\n\nexport type ThreadListGridProps = ComponentProps<typeof parts.Grid>;\n\n/** A `ThreadListHeading`, `ThreadListRow` or `ThreadListFold` for each row in view, unless you pass children. */\nexport function ThreadListGrid({ children = DEFAULT_ROWS, ...props }: ThreadListGridProps) {\n  return <parts.Grid {...props}>{children}</parts.Grid>;\n}\n\nconst DEFAULT_ROWS = ({ visible, rows }: ThreadListGridState) =>\n  visible.map((item) => {\n    const type = rows[item.index]?.type;\n    if (type === \"heading\") return <ThreadListHeading key={item.key} value={item.key} />;\n    if (type === \"fold\") return <ThreadListFold key={item.key} value={item.key} />;\n    return <ThreadListRow key={item.key} value={item.key} />;\n  });\n\nexport type ThreadListHeadingProps = ComponentProps<typeof parts.Heading>;\n\n/**\n * A group's heading, by its row key, with its count when grouped by status. Memoized, so rows that didn't change aren't\n * rendered again.\n */\nexport const ThreadListHeading = memo(function ThreadListHeading(props: ThreadListHeadingProps) {\n  return (\n    <parts.Heading {...props}>\n      <parts.HeadingCell value={props.value}>{HEADING}</parts.HeadingCell>\n    </parts.Heading>\n  );\n});\n\nconst HEADING = ({ label, count }: { label: string; count: string }) => (\n  <>\n    {label}\n    {count && (\n      <>\n        {\" \"}\n        <span data-thread-list-count=\"\">{count}</span>\n      </>\n    )}\n  </>\n);\n\nexport type ThreadListFoldProps = ComponentProps<typeof parts.FoldRow>;\n\n/**\n * The row after \"Done\"'s threads: \"12 more done\", which shows a page more, then \"Show less\". Memoized, as rows are.\n */\nexport const ThreadListFold = memo(function ThreadListFold(props: ThreadListFoldProps) {\n  return (\n    <parts.FoldRow {...props}>\n      <parts.FoldCell value={props.value}>\n        <parts.Fold value={props.value}>{FOLD}</parts.Fold>\n      </parts.FoldCell>\n    </parts.FoldRow>\n  );\n});\n\nconst FOLD = ({ label }: { label: string }) => (\n  <>\n    <span data-thread-list-icon=\"fold\" aria-hidden=\"true\" />\n    {label}\n  </>\n);\n\nexport type ThreadListRowProps = Omit<ComponentProps<typeof parts.Row>, \"children\"> & {\n  /**\n   * What the link shows, a function of its `{ value, title }`. Define it once outside a render, so the row stays\n   * memoized as the list scrolls.\n   */\n  children?: (state: ThreadListLinkState) => ReactNode;\n};\n\n/**\n * A thread's row, by its id: its link, which also opens the row's menu on a right-click or Shift+F10, how long ago it\n * changed, and its More button, or Unarchive in the archived view, which takes the time's place on hover and focus.\n * Memoized, so rows that didn't change aren't rendered again.\n */\nexport const ThreadListRow = memo(function ThreadListRow({ children, ...props }: ThreadListRowProps) {\n  return (\n    <parts.Row {...props}>\n      <parts.LinkCell value={props.value}>\n        <ThreadListLink value={props.value}>{children}</ThreadListLink>\n        <parts.Editor value={props.value} type=\"text\" />\n        <parts.Time value={props.value}>{TIME}</parts.Time>\n      </parts.LinkCell>\n      <parts.MoreCell value={props.value}>\n        <parts.More value={props.value} data-kind-icon-button=\"\" data-kind-size=\"sm\">\n          {ELLIPSIS}\n        </parts.More>\n        <parts.Unarchive value={props.value}>{UNARCHIVE}</parts.Unarchive>\n      </parts.MoreCell>\n    </parts.Row>\n  );\n});\n\nconst TIME = ({ label }: ThreadListTimeState) => label;\nconst UNARCHIVE = ({ label }: { label: string }) => label;\n\nexport type ThreadListLinkProps = ComponentProps<typeof parts.Link>;\n\n/** A thread's link: its title and its one mark, then its second line, unless you pass children. */\nexport function ThreadListLink({ children = DEFAULT_LINK, ...props }: ThreadListLinkProps) {\n  return <parts.Link {...props}>{children}</parts.Link>;\n}\n\nconst DEFAULT_LINK = ({ value, title }: ThreadListLinkState) => (\n  <>\n    <span data-thread-list-title=\"\">{title}</span>\n    <parts.Status value={value} />\n    <parts.Unread value={value} />\n    <parts.Summary value={value}>{SUMMARY}</parts.Summary>\n  </>\n);\n\n/** \"Approval · Run `rm -rf dist`?\": the lead, then the summary with its code. */\nconst SUMMARY = ({ lead, pieces }: ThreadListSummaryState) => (\n  <>\n    {lead}\n    {lead && pieces.length > 0 && \" · \"}\n    {pieces.map((piece, index) =>\n      index % 2 ? <code key={index}>{piece}</code> : <Fragment key={index}>{piece}</Fragment>,\n    )}\n  </>\n);\n\nexport type ThreadListMenuProps = { children?: ReactNode };\n\n/** UI SDK Menu, shared by every row, holding a `ThreadListMenuContent` unless you pass children. */\nexport function ThreadListMenu({ children = MENU_CONTENT }: ThreadListMenuProps) {\n  return <parts.Menu>{(menu) => <KindMenu {...menu}>{children}</KindMenu>}</parts.Menu>;\n}\n\nexport type ThreadListMenuContentProps = Omit<ComponentProps<typeof KindMenuContent>, \"children\"> & {\n  /** The menu's items, a function of its thread and actions: a menu item for each action by default. */\n  children?: (state: ThreadListMenuContentState) => ReactNode;\n};\n\n/** UI SDK's `MenuContent` with Rename, Pin or Unpin, Share and Delete, each while its callback is set. */\nexport function ThreadListMenuContent({ children = DEFAULT_ITEMS, ...props }: ThreadListMenuContentProps) {\n  return (\n    <parts.MenuContent>\n      {(state) => (\n        // Hidden from agents, which use the Thread List's own actions. Kept mounted, so Menu never shows up beside it.\n        <KindMenuContent\n          align=\"end\"\n          sideOffset={4}\n          finalFocus={state.finalFocus}\n          keepMounted\n          data-agent-hidden=\"\"\n          {...props}\n        >\n          {children(state)}\n        </KindMenuContent>\n      )}\n    </parts.MenuContent>\n  );\n}\n\nconst DEFAULT_ITEMS = ({ actions }: ThreadListMenuContentState) =>\n  actions.map((action) => (\n    <KindMenuItem\n      key={action.value}\n      value={action.value}\n      data-destructive={action.value === \"delete\" ? \"\" : undefined}\n    >\n      <span data-thread-list-icon={action.value} aria-hidden=\"true\" />\n      {action.label}\n    </KindMenuItem>\n  ));\n\nexport type ThreadListDialogProps = { children?: ReactNode };\n\n/**\n * The Alert Dialog Delete opens: \"Delete chat?\", the thread's title, and Cancel and Delete, unless you pass children\n * for the answers. Rendered only while `onDelete` is set and `confirmDelete` is on.\n */\nexport function ThreadListDialog({ children = DEFAULT_ANSWERS }: ThreadListDialogProps) {\n  return (\n    <parts.Dialog>\n      {({ controller, dismissible, initialFocus, finalFocus, title, description }) => (\n        <KindAlertDialog controller={controller} dismissible={dismissible}>\n          <KindAlertDialogBackdrop />\n          <KindAlertDialogContent initialFocus={initialFocus} finalFocus={finalFocus}>\n            <KindAlertDialogTitle>{title}</KindAlertDialogTitle>\n            <KindAlertDialogDescription>{description}</KindAlertDialogDescription>\n            {children}\n          </KindAlertDialogContent>\n        </KindAlertDialog>\n      )}\n    </parts.Dialog>\n  );\n}\n\nexport type ThreadListDialogErrorProps = ComponentProps<typeof parts.DialogError>;\n\n/** \"Couldn't delete. Try again.\" after a delete fails, unless you pass children. */\nexport function ThreadListDialogError({\n  children = \"Couldn't delete. Try again.\",\n  ...props\n}: ThreadListDialogErrorProps) {\n  return <parts.DialogError {...props}>{children}</parts.DialogError>;\n}\n\nexport type ThreadListDialogCancelProps = ComponentProps<typeof parts.DialogCancel>;\n\n/** Closes the dialog. Reads \"Cancel\" unless you pass children. */\nexport function ThreadListDialogCancel({ children = \"Cancel\", ...props }: ThreadListDialogCancelProps) {\n  return <parts.DialogCancel {...props}>{children}</parts.DialogCancel>;\n}\n\nexport type ThreadListDialogDeleteProps = ComponentProps<typeof parts.DialogDelete>;\n\n/** Calls `onDelete`. Reads \"Delete\" unless you pass children. */\nexport function ThreadListDialogDelete({ children = \"Delete\", ...props }: ThreadListDialogDeleteProps) {\n  return <parts.DialogDelete {...props}>{children}</parts.DialogDelete>;\n}\n\nexport type ThreadListEndProps = ComponentProps<typeof parts.End>;\n\n/** After the rows while loading more: \"Loading more chats\", or \"Couldn't load more chats\" and Retry. */\nexport function ThreadListEnd({\n  children = ({ status }) =>\n    status === \"loading\" ? (\n      <>\n        <span aria-hidden=\"true\" data-status-mark=\"\" data-status=\"running\" />\n        Loading more chats\n      </>\n    ) : (\n      <>\n        Couldn't load more chats\n        <ThreadListRetry />\n      </>\n    ),\n  ...props\n}: ThreadListEndProps) {\n  return <parts.End {...props}>{children}</parts.End>;\n}\n\nexport type ThreadListRetryProps = ComponentProps<typeof parts.Retry>;\n\n/** Calls `onLoadMore` again. Reads \"Retry\" unless you pass children. */\nexport function ThreadListRetry({ children = \"Retry\", ...props }: ThreadListRetryProps) {\n  return <parts.Retry {...props}>{children}</parts.Retry>;\n}\n\n// Shared, so an update doesn't render the default parts' wrappers again.\nconst NEW_CHAT = (\n  <>\n    <span data-thread-list-icon=\"new\" aria-hidden=\"true\" />\n    New chat\n  </>\n);\nconst ELLIPSIS = <span data-thread-list-icon=\"more\" aria-hidden=\"true\" />;\nconst MENU_CONTENT = <ThreadListMenuContent />;\nconst DEFAULT_ANSWERS = (\n  <div data-thread-list-answers=\"\">\n    <ThreadListDialogError />\n    <ThreadListDialogCancel />\n    <ThreadListDialogDelete />\n  </div>\n);\nconst DEFAULT_PARTS = (\n  <>\n    <ThreadListNew />\n    <ThreadListEmpty />\n    <ThreadListViewport>\n      <ThreadListGrid />\n      <ThreadListEnd />\n    </ThreadListViewport>\n    <ThreadListMenu />\n    <ThreadListDialog />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/thread-list.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
