@characterxyz/widget

中文文档
0.10.1发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 3064

Character XYZ in any site: the agent in the corner with chat and voice calls. One script tag, or a Web Component.

原始使用文档
文档目录9 节
  1. Script tag (no build step)
  2. Binding the page
  3. npm
  4. Settings
  5. Styling
  6. Events
  7. Signed-in visitors
  8. Security
  9. License

@characterxyz/widget

Put your Character XYZ agent on any website: the character in the corner, text chat that streams, and real-time voice calls with a fair queue when every line is busy. One Web Component in a Shadow DOM, so it works in plain HTML, React, Vue, Svelte, Angular or anything else, and nothing of your page's CSS leaks in or out. 34 KB gzipped, everything included; it starts once the page is idle.

Create a publishable key, choose the sites it may run on and pick the look in Character XYZ › Settings › Developers.

Script tag (no build step)

<script src="https://unpkg.com/@characterxyz/widget@0/dist/cx.js" data-key="cxyz_pk_live_…" async></script>

Settings go on the tag as data-* attributes: data-display="full", data-accent="#e11d48", data-position="bottom-left", data-mode="dark", data-show-call="false", data-agent="agent_…". Drive it from your own buttons with CharacterXYZ.open('chat') or CharacterXYZ.open('call').

Binding the page

// Who this is / what is true now. Stays in scope for every later turn.
CharacterXYZ.identify({ id: 'u_42', name: 'Asha', traits: { plan: 'pro' } });
CharacterXYZ.setContext({ page: '/pricing', cart: { items: 2 } });

// Something they did. Only names the agent's graph declares.
CharacterXYZ.track('pricing_viewed', { plan: 'pro' });

// Something the agent may ask the page to do.
CharacterXYZ.registerAction('openCart', async ({ itemId }) => { cart.open(itemId); return { opened: true }; });

track is fire-and-forget (void), sends an idempotency id, and survives a navigating click. An awaited page action runs your handler and posts the result back on the same request; the agent's reply follows. The graph nodes are On Site Event and Client Action.

npm

npm install @characterxyz/widget
import { mount } from '@characterxyz/widget';

const widget = mount({ publishableKey: 'cxyz_pk_live_…', accent: '#e11d48' });
widget.open('chat'); // or 'call'; widget.close(); widget.destroy()

Using React or Next.js? Install @characterxyz/react instead; it includes this package.

Settings

The defaults come from the key (set on the Embed page); anything passed here overrides them for this site.

SettingValues
agentIdWhich of the key's agents. Default: the key's first
displaybubble · half · full (how much of her shows)
launcher, positionLauncher style; bottom-right · bottom-left
accent, mode, radius, fontColour, auto · light · dark, corner radius, font family
showChat, showCall, brandingTurn chat, calls or the footer off
offsetX, offsetY, zIndex, containerPlacement
movableVisitors can drag her anywhere along the bottom (hold first on touch); let go higher up and she falls back down. The chat then opens from where she stands. Off by default

What the agent says (persona, knowledge, greeting) is the agent's own, set in Character XYZ.

Styling

CSS tokens on the element: character-xyz { --cx-accent: …; --cx-font: …; --cx-radius: … }. Parts: ::part(launcher | presence | actions | panel | header | composer | banner | message | message-agent | message-visitor | message-event | event | greeting).

Events

The element fires bubbling events: cx-ready, cx-open, cx-close, cx-call ({phase, position, endReason}) and cx-error.

Signed-in visitors

Mint the session on your server with @characterxyz/server, then: mount({ getSessionToken: () => fetch('/api/characterxyz/session').then((r) => r.json()) }). Their chat history then follows them across devices.

Security

A publishable key (cxyz_pk_…) is public by design: it works only from the sites listed on it and exchanges for a 15-minute session bound to that site. Never put a secret key (cxyz_sk_…) in a page; the SDK refuses to run with one.

License

MIT

版本与发布记录

@characterxyz/widget 共发布 17 个版本,首次发布于 2026/10/12;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.1latest2026/11/063 天前
0.10.02026/11/017 天前
0.9.12026/11/017 天前
0.9.02026/11/018 天前
0.8.02026/10/2614 天前
0.7.32026/10/2514 天前

关于 @characterxyz/widget 的常见问题

@characterxyz/widget 是什么?

Character XYZ in any site: the agent in the corner with chat and voice calls. One script tag, or a Web Component.

如何安装 @characterxyz/widget?

在项目目录运行 npm install @characterxyz/widget,或使用 pnpm add / yarn add / bun add。

@characterxyz/widget 支持 TypeScript 吗?

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

@characterxyz/widget 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@characterxyz/widget 可以商用吗?

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

@characterxyz/widget 的下载量有多少?

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

@characterxyz/widget 还在维护吗?

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