@bootstrapware/answers

中文文档
0.2.13发布于 2026/10/27MITTypeScriptES Module零依赖近 30 天下载 2008

Embeddable source-backed Q&A for your site: React widget plus a server engine (crawl, hybrid search, grounded OpenAI answers with citations) for BYO backends.

原始使用文档
文档目录3 节
  1. Local
  2. Script
  3. BYO

@bootstrapware/answers

Visitors ask a question. The widget shows a cited answer, or an explicit fallback when nothing matches.

Local mode is free. BYO is $9.99 / month (you store knowledge and answers). Hosted is $19.99 / month. Hosted stores approved sources, the derived index, visitor questions, optional conversations, unanswered items, and citations. Hosted includes 2,500 answers per workspace each month, 1 GiB of knowledge and index, 2,000 sources, 4,000 indexed chunks per app, 20 MiB per file, and 30 days of conversation history. Test keys are free. The React package does not call Hosted ask by itself. Pass createLocalAdapter() or your own adapter.

pnpm add @bootstrapware/answers

Non-React pages can use the Hosted script embed instead (see Script below).

Peer dependencies: react and react-dom (>= 18).

Local

import { Answers, createLocalAdapter } from "@bootstrapware/answers";
import "@bootstrapware/answers/styles.css";

<Answers adapter={createLocalAdapter()} />

The default presentation is a closed corner launcher. presentation can be launcher, section, modal, or window. Modal, window, and launcher start closed unless defaultOpen.

The local adapter is a deterministic sample for Northwind Outfitters (hours, returns, shipping). It does not call the network.

Script

pnpm build writes dist/answers.iife.js. A non-React page can mount the same component:

<div id="answers"></div>
<script src="./dist/answers.iife.js"></script>
<script>
  BootstrapwareAnswers.mount(document.getElementById("answers"), {});
</script>

The hosted script is GET https://answers.bootstrapware.co/embed/v1.js.

BYO

Run the engine on your server with your OpenAI key. Questions, knowledge, and the key stay on your infrastructure.

// app/api/answers/route.ts (Next.js) — any runtime with fetch works
import { createAnswersBackend } from "@bootstrapware/answers/server";

const answers = createAnswersBackend({
  siteName: "Acme",
  openaiApiKey: process.env.OPENAI_API_KEY, // server env only
  sitemap: "https://acme.com/sitemap.xml", // or urls: [...], or documents: [{ id, title, url, text }]
  qa: [{ question: "Do you offer refunds?", answer: "Yes, within 14 days of purchase." }],
});

export const POST = (request: Request) => answers.handler(request);

The index is built on the first question and kept in memory. Call answers.refresh() after your content changes (it returns { pages, chunks, skipped }; skipped lists every page left out and why, including a URL that redirects to a different page, and onRefresh receives the same report after the automatic first build), or save answers.index.toJSON() and pass it back as snapshot to skip re-embedding on restart. Pass retrieve to use your own vector store instead.

Answers come only from the indexed passages. refresh() also fetches /llms.txt and /llms-full.txt for each origin in urls or the sitemap when the host publishes them as text or Markdown, and ignores a missing file. A draft that cites something it did not retrieve, or states a price or number that is not in a cited passage and does not follow from cited figures (a single-step percent-off or percent-of of a cited amount, rounded to the nearest cent, or a sequential stack total with each line rounded to the nearest cent), is rejected and the visitor gets the fallback. The same number with a comma, dot, space, or apostrophe as the thousands separator counts as the figure in the source, and a comma decimal such as 19,99 counts as $19.99. A stack total that depends on billing order is rejected unless the visitor set the order, the answer says order matters, or the answer itemizes lines that sum to that total. Custom Q&A is always considered, and a matching entry is answered first. When the sources are silent on a yes/no question, the answer says the site does not state it (with the support contact if a source has one). How-to questions cite the docs page; no new code is written.

Custom Q&A can change at runtime without a refresh: call await answers.upsertQa({ id, question, answer }), answers.removeQa(id), or answers.setQa([...]) from your save handler. Only the changed entry is embedded and it answers on the next question. Relevant custom Q&A are always offered to the model, even when many page passages outrank them, and that includes setups that pass their own retrieve.

Then point the widget at that route:

<Answers
  appId="ana_..."
  adapter={createByoAdapter({
    ask: async ({ sessionId, question, pageContext }) => {
      const response = await fetch("/api/answers", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ sessionId, question, pageContext }),
      });
      return response.json();
    },
  })}
/>

Question text stays on your backend. pageContext is the page URL and title only.

版本与发布记录

@bootstrapware/answers 共发布 15 个版本,首次发布于 2026/10/06;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.2.13latest2026/10/2711 天前
0.2.122026/10/2612 天前
0.2.112026/10/2018 天前
0.2.102026/10/1424 天前
0.2.92026/10/1424 天前
0.2.82026/10/1425 天前

关于 @bootstrapware/answers 的常见问题

@bootstrapware/answers 是什么?

Embeddable source-backed Q&A for your site: React widget plus a server engine (crawl, hybrid search, grounded OpenAI answers with citations) for BYO backends.

如何安装 @bootstrapware/answers?

在项目目录运行 npm install @bootstrapware/answers,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)、react-dom(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bootstrapware/answers 支持 TypeScript 吗?

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

@bootstrapware/answers 支持 ESM 还是 CommonJS?

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

@bootstrapware/answers 可以商用吗?

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

@bootstrapware/answers 的下载量有多少?

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

@bootstrapware/answers 还在维护吗?

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