{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reasoning-web",
  "title": "Reasoning (Web Components)",
  "description": "The model's thinking as a step, with its thoughts streamed as markdown.",
  "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/markdown-web"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/reasoning.ts",
      "content": "import { reasoningPrimitive, type StepApi, type StepOpenChangeReason } from \"@kind-ui/agent-ui/core\";\nimport { createParts, wrappedButton } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiChangeEvent, UiElement } from \"@ui-sdk/web/events\";\nimport { defineMarkdown, type KindMarkdownElement } from \"./markdown\";\n\nconst DEFAULT_PARTS = `<kind-reasoning-trigger><button><kind-reasoning-icon></kind-reasoning-icon><kind-reasoning-title></kind-reasoning-title></button></kind-reasoning-trigger><kind-reasoning-content><kind-markdown></kind-markdown></kind-reasoning-content>`;\n\n// Titles this element filled in. A title someone wrote text into keeps it, as React's `ReasoningTitle` children do.\n// Kept across instances, because UI SDK rebuilds one when the element returns to the page.\nconst owned = new WeakSet<Element>();\n\n/**\n * `<kind-reasoning status=\"…\" text=\"…\">` fills in its trigger and content when it has no children. It writes its\n * title into an empty `<kind-reasoning-title>`, and its `text` into a `<kind-markdown>` inside its content.\n */\nexport function defineReasoning(): void {\n  if (customElements.get(\"kind-reasoning\")) return;\n  defineMarkdown();\n  createParts(reasoningPrimitive, {\n    root: {\n      tag: \"kind-reasoning\",\n      state: {\n        open: {\n          get: (api) => api.isOpen(),\n          set: (api, open) => api.setOpen(!!open),\n        },\n      },\n      api: [\"isOpen\", \"setOpen\", \"expand\", \"collapse\", \"toggle\"],\n      render: (el, instance) => {\n        if (!el.firstElementChild) el.innerHTML = DEFAULT_PARTS;\n        const draw = () => {\n          const { title, text, status } = instance.get();\n          const titlePart = el.querySelector(\"kind-reasoning-title\");\n          if (titlePart && (owned.has(titlePart) || !titlePart.textContent)) {\n            owned.add(titlePart);\n            if (titlePart.textContent !== title) titlePart.textContent = title;\n          }\n          const markdown = el.querySelector<KindMarkdownElement>(\n            \":scope > kind-reasoning-content > kind-markdown\",\n          );\n          if (markdown) {\n            if (markdown.source !== text) markdown.source = text;\n            const streaming = status === \"running\";\n            if (markdown.streaming !== streaming) markdown.streaming = streaming;\n          }\n        };\n        draw();\n        const unsubscribe = instance.subscribe(draw);\n        const arrivals = new MutationObserver((records) => {\n          // The blocks `kind-markdown` renders for each chunk aren't parts.\n          const arrived = records.some(\n            (record) =>\n              !(record.target instanceof Element && record.target.closest(\"kind-markdown\")) &&\n              [...record.addedNodes].some((node) => node instanceof Element),\n          );\n          if (arrived) draw();\n        });\n        arrivals.observe(el, { childList: true, subtree: true });\n        return () => {\n          unsubscribe();\n          arrivals.disconnect();\n        };\n      },\n    },\n    trigger: { tag: \"kind-reasoning-trigger\", target: wrappedButton, display: \"contents\" },\n    icon: \"kind-reasoning-icon\",\n    title: \"kind-reasoning-title\",\n    content: \"kind-reasoning-content\",\n  });\n}\n\nexport type KindReasoningEvents = { openchange: UiChangeEvent<boolean, StepOpenChangeReason> };\n\nexport interface KindReasoningElement\n  extends UiElement<KindReasoningEvents>,\n    AttributeProperties<typeof reasoningPrimitive, \"api\" | \"open\"> {\n  open: boolean;\n  api: Pick<StepApi, \"isOpen\" | \"setOpen\" | \"expand\" | \"collapse\" | \"toggle\">;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-reasoning\": KindReasoningElement;\n    \"kind-reasoning-trigger\": HTMLElement;\n    \"kind-reasoning-icon\": HTMLElement;\n    \"kind-reasoning-title\": HTMLElement;\n    \"kind-reasoning-content\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/reasoning.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
