@handrail-chat/client

中文文档
0.4.0发布于 2026/10/17UNLICENSEDTypeScriptES Module零依赖近 30 天下载 8268

Framework-agnostic client for Handrail — transport, session exchange, and conversation state.

原始使用文档
文档目录5 节
  1. What it gives you
  2. The transport seam
  3. Context for the agent
  4. Notes
  5. License

@handrail-chat/client

The framework-agnostic core of Handrail — an in-app help surface where customers ask for help in your product and agents answer from Slack.

If you are building with React, install @handrail-chat/react instead. It depends on this package and gives you a panel, a launcher and hooks. This one is for building your own UI, or a binding for another framework.

bun add @handrail-chat/client

No runtime dependencies.

What it gives you

import { createHandrail, createSseTransport } from "@handrail-chat/client";

const handrail = createHandrail({
  transport: createSseTransport({
    baseUrl: "https://api.handrail.chat",
    getToken: async () => (await fetch("/api/handrail-token")).json().then((r) => r.token),
  }),
});

handrail.subscribe(() => render(handrail.getState()));
await handrail.start();

await handrail.send("my export keeps failing");

getState() returns messages, conversations, connection state and status. subscribe fires on every change. There is no state library here and none is forced on you.

See the React package's README for the token contract — what your backend has to sign, and why.

The transport seam

Transport is an interface with two implementations. SseTransport talks to a real Handrail; MockTransport is memory, and needs no server, database or Slack. Nothing above the transport can tell them apart, which is what makes the same components drivable from fixtures in tests and stories.

import { createMockTransport } from "@handrail-chat/client";

const transport = createMockTransport();
const handrail = createHandrail({ transport });

transport.receiveAgentMessage("Looking into it now");

Context for the agent

Two ways to tell whoever answers in Slack something the customer did not type. Neither is ever shown to the customer. The React package's README covers both in depth, with a full example.

// An outcome the agent must not miss. Its own Slack message; works with the
// panel closed and on a resolved conversation.
await handrail.postNote('👍 "Exchanging tickets" solved it', { conversationId });

// What the customer is doing while they talk. Grey lines in one growing Slack
// message; sent only while the panel is open and the conversation unresolved.
handrail.setPanelOpen(true); // from your panel, as it opens and closes
handrail.trackActivity({ kind: "page", text: "Order #1234", url: location.href });

trackActivity never throws and returns nothing: events are batched for a quarter of a second, and a failed send is dropped rather than retried.

Notes

Live updates use fetch with a stream, not EventSource — the latter cannot set headers, which would force the session token into a query string where it lands in access logs and browser history.

start() never rejects, so it is safe to call without awaiting. If the widget cannot connect — your getToken throws, or the network is down — status is "error" and error says why, and it retries with backoff until it can. Gate a support launcher on status, not on whether start() resolved.

Reconnecting refetches a delta, not the whole history.

Sends are optimistic and reconcile by a client-generated id, so there is no duplicate when the server's echo arrives. A failed send stays in state marked failed with its clientId, ready for retry.

License

UNLICENSED — not yet open source.

版本与发布记录

@handrail-chat/client 共发布 5 个版本,首次发布于 2026/09/08;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.4.0latest2026/10/171 个月前
0.3.12026/10/061 个月前
0.3.02026/09/271 个月前
0.2.02026/09/271 个月前
0.1.02026/09/082 个月前

关于 @handrail-chat/client 的常见问题

@handrail-chat/client 是什么?

Framework-agnostic client for Handrail — transport, session exchange, and conversation state.

如何安装 @handrail-chat/client?

在项目目录运行 npm install @handrail-chat/client,或使用 pnpm add / yarn add / bun add。

@handrail-chat/client 支持 TypeScript 吗?

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

@handrail-chat/client 支持 ESM 还是 CommonJS?

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

@handrail-chat/client 可以商用吗?

@handrail-chat/client 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@handrail-chat/client 的下载量有多少?

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

@handrail-chat/client 还在维护吗?

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