{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "connection-status-web",
  "title": "Connection Status (Web Components)",
  "description": "A pill over a conversation that says the connection dropped, counts down and retries.",
  "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"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/web/connection-status.ts",
      "content": "import {\n  type ConnectionStatusRetryDetails,\n  connectionStatusPrimitive,\n  connectionStatusText,\n} from \"@kind-ui/agent-ui/core\";\nimport { createParts, type UiActionDetail, wrappedButton } from \"@ui-sdk/web\";\nimport type { AttributeProperties, UiElement } from \"@ui-sdk/web/events\";\n\nconst PARTS = [\n  [\"kind-connection-status-mark\", \"\"],\n  [\"kind-connection-status-text\", \"\"],\n  [\"kind-connection-status-retry\", \"<button></button>\"],\n] as const;\n\n// The text and Retry labels this element filled in. One someone wrote text into keeps it, as React's children do.\n// Kept across instances, because UI SDK rebuilds one when the element returns to the page.\nconst owned = new WeakSet<Element>();\n\nconst fill = (el: Element | null, text: string) => {\n  if (!el || (!owned.has(el) && el.textContent)) return;\n  owned.add(el);\n  if (el.textContent !== text) el.textContent = text;\n};\n\n/**\n * `<kind-connection-status state=\"…\">` adds its mark, its words and Retry, unless it has them, and fills in the\n * words and Retry's label unless they hold text of their own. The `can-retry` attribute\n * shows Retry, which fires `connectionretry`: call `event.detail.waitUntil(promise)` to keep it pending until the promise\n * settles. `labels` is a property.\n */\nexport function defineConnectionStatus(): void {\n  if (customElements.get(\"kind-connection-status\")) return;\n  createParts(connectionStatusPrimitive, {\n    root: {\n      tag: \"kind-connection-status\",\n      kinds: { canRetry: \"boolean\" },\n      // Conversation fires its own `retry`, which a capture listener on it would hear from this element too.\n      events: { onRetry: \"connectionretry\" },\n      // Without the attribute the callback is left out; with it, `@ui-sdk/web` fills it in with an event.\n      options: (el) => ((el as KindConnectionStatusElement).canRetry ? {} : { onRetry: undefined }),\n      render: (el, instance) => {\n        let after: Element | null = null;\n        for (const [tag, inner] of PARTS) {\n          let part = el.querySelector(`:scope > ${tag}`);\n          if (!part) {\n            part = document.createElement(tag);\n            part.innerHTML = inner;\n            if (after) after.after(part);\n            else el.prepend(part);\n          }\n          after = part;\n        }\n        const text = el.querySelector(\":scope > kind-connection-status-text\");\n        const retry = el.querySelector(\":scope > kind-connection-status-retry > button\");\n        // Reads the live `seconds`, as React's text part does.\n        const draw = () => {\n          const state = instance.get();\n          fill(text, connectionStatusText(state));\n          fill(retry, state.labels.retry);\n        };\n        draw();\n        return instance.subscribe(draw);\n      },\n    },\n    mark: \"kind-connection-status-mark\",\n    text: \"kind-connection-status-text\",\n    retry: { tag: \"kind-connection-status-retry\", target: wrappedButton, display: \"contents\" },\n  });\n}\n\nexport type KindConnectionStatusEvents = {\n  connectionretry: CustomEvent<ConnectionStatusRetryDetails & Pick<UiActionDetail, \"waitUntil\">>;\n};\n\nexport interface KindConnectionStatusElement\n  extends UiElement<KindConnectionStatusEvents>,\n    AttributeProperties<typeof connectionStatusPrimitive> {\n  canRetry: boolean;\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    \"kind-connection-status\": KindConnectionStatusElement;\n    \"kind-connection-status-mark\": HTMLElement;\n    \"kind-connection-status-text\": HTMLElement;\n    \"kind-connection-status-retry\": HTMLElement;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/web/connection-status.ts"
    }
  ],
  "meta": {
    "layer": "web"
  },
  "type": "registry:ui"
}
