@copilotkit/web-components

中文文档
1.86.0发布于 2026/11/11MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 166万

Framework-agnostic shadow-DOM web components for CopilotKit - includes the threads drawer element

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Inbound properties (DOMAIN state — owned by the consumer)
  4. Outbound events (INTENT — bubbling + composed CustomEvent s)
  5. Theming (hybrid)
  6. Mobile + a11y

@copilotkit/web-components

Framework-agnostic, shadow-DOM Lit custom elements for CopilotKit.

This package currently ships <copilotkit-threads-drawer> — a public, self-contained, controlled threads drawer. It is a pure VIEW: domain data flows in as properties and user intent flows out as DOM CustomEvents. It imports no React, Angular, or @copilotkit/core code and renders correctly in any host page, surviving hostile host CSS (all: unset, Tailwind preflight !important).

Install

npm install @copilotkit/web-components lit

lit is a peer/runtime dependency so the host dedupes a single Lit runtime.

Usage

import { defineCopilotKitThreadsDrawer } from "@copilotkit/web-components/threads-drawer";

defineCopilotKitThreadsDrawer(); // registers <copilotkit-threads-drawer> (idempotent)
<copilotkit-threads-drawer active-thread-id="t-123"></copilotkit-threads-drawer>
<script>
  const drawer = document.querySelector("copilotkit-threads-drawer");
  drawer.threads = [
    {
      id: "t-123",
      name: "My thread",
      archived: false,
      createdAt: "...",
      updatedAt: "...",
    },
  ];
  drawer.addEventListener("thread-selected", (e) => open(e.detail.threadId));
  drawer.addEventListener("new-thread", () => createThread());
</script>

Inbound properties (DOMAIN state — owned by the consumer)

propertytypenotes
threadsDrawerThread[]the element re-orders + filters authoritatively
loadingbooleaninitial-fetch loading
errorstring | nullinitial-fetch error → actionable Retry
activeThreadIdstring | nulldrives selection highlight
licensedbooleanfalse → upsell replaces the list
fetchingMorebooleanin-flight pagination
fetchMoreErrorstring | nullinline "couldn't load more — retry"
openbooleanexternally controllable (mobile coordination)
collapsedbooleandesktop collapse-to-rail

Outbound events (INTENT — bubbling + composed CustomEvents)

thread-selected, archive, unarchive, delete (after in-element confirm), new-thread, filter-change, open-change, retry ({ scope }), upsell.

The element owns VIEW state: open/collapsed, the Active/All filter, the confirm-delete dialog, and per-row entry/reveal animations.

Theming (hybrid)

  • CSS variables pierce the shadow boundary — set --cpk-drawer-* (-bg, -fg, -surface, -accent, -primary, -danger, -border, -ring, -radius, -width, -font-family, …) from the host.
  • ::part() hooks on structural nodes (root, header, list, row, row-name, confirm-dialog, backdrop, …).
  • Named slots: header, footer, empty, upsell, memories, plus a per-row slot row:{id} that projects wrapper-provided row content while the element keeps the selection/archived/animation chrome around it.

The built-in default skin's token values are derived at build time from react-core's canonical theme (packages/react-core/src/v2/styles/globals.css) by scripts/generate-tokens.ts, which writes the checked-in src/threads-drawer/generated-tokens.ts. Run pnpm run gen:tokens to regenerate; generated-tokens.test.ts fails if the checked-in values drift from react-core.

Mobile + a11y

At/below 768px the drawer is an off-canvas modal overlay with backdrop, Escape close, scroll-lock, and a focus trap (mobile only) that operates over the composed/flattened tree so slotted rows are included. On desktop it is an in-flow region with collapse-to-rail — not a modal (no focus trap, no scroll-lock).

版本与发布记录

@copilotkit/web-components 共发布 136 个版本,首次发布于 2026/07/02;过去 12 个月发布了 136 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.86.0latest2026/11/11今天
2.0.0-rc.40next2026/11/11今天
2.0.0-rc.392026/11/10今天
2.0.0-rc.382026/11/10今天
2.0.0-rc.372026/11/091 天前
2.0.0-rc.362026/11/064 天前

其他发布通道:canary → 1.84.2-canary.openbot-intel-fixes,next → 2.0.0-rc.40。

关于 @copilotkit/web-components 的常见问题

@copilotkit/web-components 是什么?

Framework-agnostic shadow-DOM web components for CopilotKit - includes the threads drawer element

如何安装 @copilotkit/web-components?

在项目目录运行 npm install @copilotkit/web-components,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:lit(^3.3.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@copilotkit/web-components 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@copilotkit/web-components 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@copilotkit/web-components 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@copilotkit/web-components 可以商用吗?

@copilotkit/web-components 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@copilotkit/web-components 的下载量有多少?

根据 npm 官方下载统计,@copilotkit/web-components 在 2026/10/11 – 2026/11/09 这 30 天内被下载 1,660,487 次,日均约 55,350 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@copilotkit/web-components 还在维护吗?

最新版本 1.86.0 发布于 2026/11/11(今天);至今共发布 136 个版本,其中过去 12 个月发布了 136 个;首次发布于 2026/07/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。