{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-search-web",
  "title": "Thread Search (Web Components)",
  "description": "A Search chats dialog over the threads, grouped by date, with New chat and a shortcut.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/web@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/picker-web",
    "@kind-ui/internal-command-web"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/thread-search.ts",
      "content": "import {\n  type PickerBaseApi,\n  type PickerOpenChangeReason,\n  type PickerRow,\n  type ThreadSearchApi,\n  type ThreadSearchOptions,\n  type ThreadSearchSelectReason,\n  type ThreadSearchState,\n  threadSearchPrimitive,\n} from \"@kind-ui/agent-ui/core\";\nimport type { CommandQueryChangeReason } from \"@ui-sdk/core/command\";\nimport { createParts, type RootOptions } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiChangeEvent, UiElement } from \"@ui-sdk/web/events\";\nimport { defineInternalCommand } from \"./internal/command\";\nimport { pickerElements } from \"./picker\";\n\ntype P = typeof threadSearchPrimitive;\n\nconst TAG = \"kind-thread-search\";\n\nconst template = `<${TAG}-trigger><button></button></${TAG}-trigger><${TAG}-backdrop hidden></${TAG}-backdrop><${TAG}-content hidden><${TAG}-command><kind-internal-command><ui-command><ui-command-input><input data-agent-hidden></ui-command-input><ui-command-empty></ui-command-empty><ui-command-list></ui-command-list></ui-command></kind-internal-command></${TAG}-command><${TAG}-hints><span><kbd>↑↓</kbd> Navigate</span><span><kbd>↵</kbd> Open</span><span><kbd>Esc</kbd> Close</span></${TAG}-hints></${TAG}-content>`;\n\n/** The trigger's label and the `shortcut`'s keys, made once and then only their text written. */\nconst drawTrigger = (button: Element, state: ThreadSearchState) => {\n  const document = button.ownerDocument;\n  let text = button.querySelector(\"[data-picker-text]\");\n  if (!text) {\n    text = document.createElement(\"span\");\n    text.setAttribute(\"data-picker-text\", \"\");\n    button.replaceChildren(text, document.createElement(`${TAG}-shortcut`));\n  }\n  if (text.textContent !== state.label) text.textContent = state.label;\n  const shortcut = button.querySelector(`${TAG}-shortcut`);\n  if (shortcut && shortcut.textContent !== state.shortcutText) shortcut.textContent = state.shortcutText;\n};\n\nconst statusMark = (document: Document, row: PickerRow) => {\n  const mark = document.createElement(`${TAG}-status`);\n  mark.setAttribute(\"value\", row.option.value);\n  return [mark];\n};\n\n/**\n * `<kind-thread-search>` fills in its trigger and dialog when it has no children. Set `threads` as a property; with\n * `can-select`, choosing a thread fires `threadselect` with its id as `detail.value`, and with `can-new`, \"New chat\"\n * fires `threadnew` with the search text. Typing fires `threadquerychange`.\n */\nexport function defineThreadSearch(): void {\n  if (customElements.get(TAG)) return;\n  defineInternalCommand();\n  const elements = pickerElements<P>(\n    TAG,\n    { onSelect: \"threadselect\", onNew: \"threadnew\", onQueryChange: \"threadquerychange\" },\n    {\n      template,\n      can: { canSelect: \"onSelect\", canNew: \"onNew\" },\n      state: {\n        open: {\n          get: (api) => (api as PickerBaseApi).isOpen(),\n          set: (api, open) => (api as PickerBaseApi).setOpen(!!open),\n        },\n      } as RootOptions<P>[\"state\"],\n      api: [\"isOpen\", \"setOpen\"],\n      drawTrigger: (button, state) => drawTrigger(button, state as ThreadSearchState),\n      // The status mark ends the row, after the date, since Command hides an item's icon from assistive technology and\n      // a status needs its words.\n      icon: () => [],\n      trailing: (document, row) => (row.icon === undefined ? [] : statusMark(document, row)),\n      parts: {\n        backdrop: `${TAG}-backdrop`,\n        shortcut: `${TAG}-shortcut`,\n        hints: `${TAG}-hints`,\n        status: `${TAG}-status`,\n      },\n    },\n  );\n  // A `false` property otherwise reads as a missing attribute.\n  createParts(threadSearchPrimitive, { ...elements, root: { ...elements.root, defaults: { filter: true } } });\n}\n\nexport type KindThreadSearchEvents = {\n  threadselect: UiChangeEvent<string, ThreadSearchSelectReason>;\n  threadnew: UiChangeEvent<string, ThreadSearchSelectReason>;\n  threadquerychange: UiChangeEvent<string, CommandQueryChangeReason>;\n  openchange: UiChangeEvent<boolean, PickerOpenChangeReason>;\n};\n\nexport interface KindThreadSearchElement\n  extends UiElement<KindThreadSearchEvents>,\n    AttributeProperties<P, \"api\" | \"open\" | \"threads\" | \"groupLabels\"> {\n  threads?: ThreadSearchOptions[\"threads\"];\n  groupLabels?: ThreadSearchOptions[\"groupLabels\"];\n  open: boolean;\n  /** Whether a person can choose a thread, which fires `threadselect`. */\n  canSelect: boolean;\n  /** Whether \"New chat\" shows, which fires `threadnew`. */\n  canNew: boolean;\n  api: Pick<ThreadSearchApi, \"isOpen\" | \"setOpen\">;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-thread-search\": KindThreadSearchElement;\n    \"kind-thread-search-trigger\": HTMLElement;\n    \"kind-thread-search-backdrop\": HTMLElement;\n    \"kind-thread-search-content\": HTMLElement;\n    \"kind-thread-search-viewport\": HTMLElement;\n    \"kind-thread-search-command\": HTMLElement;\n    \"kind-thread-search-item\": HTMLElement;\n    \"kind-thread-search-note\": HTMLElement;\n    \"kind-thread-search-shortcut\": HTMLElement;\n    \"kind-thread-search-hints\": HTMLElement;\n    \"kind-thread-search-status\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/thread-search.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
