@boldare/askdare 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +14 -4
  3. package/dist/cli.js +19 -6
  4. package/dist/define-tool.js +677 -7
  5. package/dist/embed.d.ts +1 -1
  6. package/dist/embed.js +2 -1
  7. package/dist/{store.d.ts → events.d.ts} +127 -52
  8. package/dist/index.d.ts +28 -2
  9. package/dist/index.js +82 -1
  10. package/dist/next.d.ts +22 -11
  11. package/dist/next.js +537 -139
  12. package/dist/react.d.ts +24 -4
  13. package/dist/react.js +126 -18
  14. package/dist/root.js +169 -37
  15. package/dist/tool-results.d.ts +11 -1
  16. package/dist/ui/askdare.css +9 -1
  17. package/dist/ui/avatar.tsx +1 -1
  18. package/dist/ui/chat.tsx +1 -1
  19. package/dist/ui/confirm.tsx +1 -1
  20. package/dist/ui/context.ts +1 -1
  21. package/dist/ui/feedback.tsx +1 -1
  22. package/dist/ui/footer.tsx +3 -15
  23. package/dist/ui/header.tsx +1 -1
  24. package/dist/ui/icons.tsx +1 -1
  25. package/dist/ui/index.ts +1 -1
  26. package/dist/ui/message.tsx +1 -1
  27. package/dist/ui/panel.tsx +3 -1
  28. package/dist/ui/welcome.tsx +1 -1
  29. package/docs/accessibility.md +83 -0
  30. package/docs/cli.md +4 -3
  31. package/docs/compliance.md +160 -0
  32. package/docs/configuration.md +47 -2
  33. package/docs/costs.md +8 -1
  34. package/docs/custom-store.md +2 -0
  35. package/docs/embedding.md +2 -0
  36. package/docs/feedback.md +1 -1
  37. package/docs/going-public.md +15 -3
  38. package/docs/guardrails.md +128 -0
  39. package/docs/migrating-from-openai-assistant.md +1 -1
  40. package/docs/privacy.md +26 -2
  41. package/docs/react.md +7 -1
  42. package/docs/styling.md +2 -2
  43. package/docs/support.md +3 -3
  44. package/docs/texts.md +100 -96
  45. package/docs/troubleshooting.md +30 -3
  46. package/llms.txt +12 -9
  47. package/package.json +1 -1
  48. package/skills/askdare/SKILL.md +9 -2
@@ -23,10 +23,10 @@ The codes are stable. The texts are the English defaults; the widget shows them
23
23
  | Code | HTTP | The chat says | See |
24
24
  | --- | --- | --- | --- |
25
25
  | `invalid_input` | 400 | "The request was invalid.", or a specific text such as "Messages can be up to {max} characters." | [Attachments are rejected](#attachments-are-rejected) |
26
- | `unauthorized` | 401 | "Authentication is required." | [Session expired](#session-expired) |
26
+ | `unauthorized` | 401 | "Authentication is required.", or "We couldn’t confirm you’re human. Please try again." | [Session expired](#session-expired), [The human check fails](#the-human-check-fails) |
27
27
  | `session_expired` | 401 | "Your session has expired. Please try again." | [Session expired](#session-expired) |
28
28
  | `not_found` | 404 | "Not found.", or "This conversation is no longer available." | [The conversation is gone](#the-conversation-is-gone) |
29
- | `content_blocked` | 422 | "This message cannot be processed." | askdare doesn't send this code in this version |
29
+ | `content_blocked` | 422 | "This message cannot be processed.", or your own text | [Guardrails](guardrails.md): moderation or a hook blocked the message or the answer |
30
30
  | `rate_limited` | 429 | "Too many messages. Please wait a moment.", or a specific text | [Too many messages](#too-many-messages) |
31
31
  | `budget_exceeded` | 429 | "The assistant is unavailable for the rest of the day." | [Unavailable for the rest of the day](#unavailable-for-the-rest-of-the-day) |
32
32
  | `internal_error` | 500 | "Something went wrong. Please try again." | The server log; also [In-memory rate limits](#in-memory-rate-limits) |
@@ -94,6 +94,19 @@ The same check reports every invalid setting as `Invalid bot "<id>": <setting> <
94
94
 
95
95
  Problems with `CHAT_SECRET` and `IDENTITY_SECRET` are also `bot_unavailable`: they stop the chat from opening a session. In development the chat shows the reason; the table in the next entry lists them.
96
96
 
97
+ ## A model is shutting down
98
+
99
+ **You see** a warning from `npx @boldare/askdare doctor`:
100
+
101
+ ```text
102
+ ! Model <model> is scheduled to shut down on 2026-12-11.
103
+ → Change model in defineBot to the replacement OpenAI recommends: https://developers.openai.com/api/docs/deprecations
104
+ ```
105
+
106
+ **Why:** OpenAI has announced a shutdown date for the bot's model, or for the transcription model of a bot with `voice` (then the fix names `voice.model`). The model still works, so this is a warning and `doctor` still exits with `0`. The date comes from the OpenAI API; askdare keeps no list of models. After that date the model stops working and the chat answers with [The assistant is unavailable](#the-assistant-is-unavailable).
107
+
108
+ **Fix:** look up the model on OpenAI's [deprecations page](https://developers.openai.com/api/docs/deprecations), which names its recommended replacement. Set the new model (for example in `ASKDARE_MODEL`, or `voice.model` in `defineBot`), test the bot, and redeploy before the date. Run `doctor` against each deployed app, since every environment may use a different model.
109
+
97
110
  ## Connection problem
98
111
 
99
112
  **You see** "Connection problem. Please try again." when sending a message, or "Could not load the previous conversation." when the chat opens.
@@ -161,9 +174,11 @@ If the console says "Load the widget as widget.js?bot=<bot id>.", the script tag
161
174
  Every limit is in [Configuration](configuration.md#limits). Some are fixed: 12 session renewals per returning visitor per hour, 20 history loads or deletions per visitor per minute, and 2 dictations per IP and 10 per bot being transcribed at once. Windows start with the first request, so a limit of one hour lasts one hour from then.
162
175
 
163
176
  Two limits have their own text:
164
- - "This conversation is too long. Please start a new one." means the conversation reached `maxTurns`.
177
+ - "This conversation is too long. Please start a new one." means the conversation reached `maxTurns`, or outgrew the model's context window (OpenAI answered `context_length_exceeded`).
165
178
  - "Another dictation is still being transcribed. Please try again in a moment." means too many dictations are being transcribed at once.
166
179
 
180
+ For a bot that checks answers (`onOutput`, or `moderation` of output), a conversation takes one turn at a time: a message sent while the previous answer is still being written or checked, such as from a second tab, gets `rate_limited` ([Guardrails](guardrails.md#streaming-while-answers-are-checked)).
181
+
167
182
  **Fix:**
168
183
  - Wait for the window to pass, or restart `next dev`: the default counters live in the server's memory.
169
184
  - Raise the limits in development only:
@@ -229,6 +244,18 @@ When a whole bot's budget or the global one runs out, the server log says so onc
229
244
 
230
245
  **Fix:** use the same `CHAT_SECRET` on every instance. When you change it, move the old value to `CHAT_SECRET_PREVIOUS` first ([Going public](going-public.md#2-secrets-and-environment)). Then reload the page.
231
246
 
247
+ ## The human check fails
248
+
249
+ Only for a bot with `security.humanVerifier` ([Configuration](configuration.md#human-check)).
250
+
251
+ **You see** "We couldn’t confirm you’re human. Please try again." (`unauthorized`), the check never appears, or every session is refused with `upstream_error` or `bot_unavailable`.
252
+
253
+ **Why and fix:**
254
+ - **The token failed**, expired or was used before: the visitor gets a new challenge with the next message. A token solved for another bot or another widget on the same site key is refused too, since its `action` differs.
255
+ - **The widget doesn't load:** a chat inside your page needs `https://challenges.cloudflare.com` in `script-src` and `frame-src` of your page's Content Security Policy. The widget's iframe adds it by itself ([Embedding](embedding.md#what-your-app-sends-back)). Check also that your domain is in the widget's hostname list in the Cloudflare dashboard.
256
+ - **Every session is refused:** `TURNSTILE_SECRET_KEY` is missing or wrong, or Cloudflare can't be reached. The check fails closed, and `onError` (or the server log) says which.
257
+ - **With `hostnames`:** an app behind a proxy that serves it under another name fails every check. Add that name, or leave `hostnames` out.
258
+
232
259
  ## The conversation is gone
233
260
 
234
261
  **You see** "This conversation is no longer available." (`not_found`), or "Could not load the previous conversation." when the chat opens.
package/llms.txt CHANGED
@@ -2,33 +2,36 @@
2
2
 
3
3
  > `@boldare/askdare` adds an AI chatbot to any website. A Next.js 16 app (App Router, Node.js runtime) serves the chat from one catch-all route; other sites embed it with one `<script>` tag. Built on the official `openai` SDK (Responses and Conversations APIs); no database.
4
4
 
5
- Set it up with `npx @boldare/askdare init` and verify it with `npx @boldare/askdare doctor`. The public API is `defineBot`, `defineTool` and `defineTheme` from `@boldare/askdare`; `createChatHandler` (with `onError`, `onUsage` and `onFeedback`) and `getChatConfig` from `@boldare/askdare/next`; `Root`, `DefaultChat`, the hooks and the primitives from `@boldare/askdare/react`; the CLI commands (`init`, `doctor`, `kb sync`, `add ui`); `upstashStore` from `@boldare/askdare-upstash` and `otelUsage` from `@boldare/askdare-otel`; the `data-*` attributes of the script tag, `askdare(…)` on the page, the `--ask-*` CSS tokens, the `data-ask-part` names and the text keys. Everything else is internal.
5
+ Set it up with `npx @boldare/askdare init` and verify it with `npx @boldare/askdare doctor`. The public API is `defineBot` (which returns a `BotHandle`), `defineTool`, `defineTheme`, `turnstile` and `ERROR_CODES` from `@boldare/askdare`; `createChatHandler` (with `onError`, `onUsage` and `onFeedback`) and `getChatConfig` from `@boldare/askdare/next`; `Root`, `DefaultChat`, the hooks and the primitives (including `Disclosure` and `HumanCheck`) from `@boldare/askdare/react`; the CLI commands (`init`, `doctor`, `kb sync`, `add ui`); `upstashStore` from `@boldare/askdare-upstash` and `otelUsage` from `@boldare/askdare-otel`; the `data-*` attributes of the script tag, `askdare(…)` on the page, the `--ask-*` CSS tokens, the `data-ask-part` names and the text keys. Everything else is internal.
6
6
 
7
7
  ## Docs
8
8
 
9
9
  - [Getting started](docs/getting-started.md): install, `init`, `.env.local`, `doctor`, embedding on other sites
10
- - [Configuration](docs/configuration.md): every `defineBot` and `createChatHandler` option, limits with defaults, environment variables
10
+ - [Configuration](docs/configuration.md): every `defineBot` and `createChatHandler` option, limits with defaults, the human check (`security.humanVerifier: turnstile({ siteKey })`, `TURNSTILE_SECRET_KEY`), `limits.requireSharedStore`, environment variables
11
11
  - [Embedding](docs/embedding.md): the script tag and its `data-*` attributes, several bots, the host page's CSP, your own page in the widget's iframe (`embedPath`, `EmbedRoot`, `embedPageHeaders`), staging and production
12
- - [CLI](docs/cli.md): `init`, `doctor`, `kb sync`, `add ui` and `usage`, with every flag
13
- - [Troubleshooting](docs/troubleshooting.md): symptoms, causes and fixes, by error code
12
+ - [CLI](docs/cli.md): `init`, `doctor` (including model shutdown dates and bots with the AI notice off), `kb sync`, `add ui` and `usage`, with every flag
13
+ - [Troubleshooting](docs/troubleshooting.md): symptoms, causes and fixes, by error code (`ERROR_CODES`)
14
14
  - [Tools](docs/tools.md): `defineTool`, Zod schemas, what a tool may trust, and `ui`: what the visitor sees of a result as a card
15
15
  - [Reply options](docs/reply-options.md): clickable answers under the latest reply, suggested by the model (`widget.replies: 'suggest'`) or defined by a tool (`defineTool({ replies })`), limits, placement, cost
16
16
  - [Signed-in visitors](docs/identity.md): `askdare('identify')`, IDENTITY_SECRET, `context.identity`
17
17
  - [Knowledge base](docs/knowledge-base.md): `npx @boldare/askdare kb sync`, vector stores, citations
18
18
  - [Attachments](docs/attachments.md): images and PDFs from visitors
19
19
  - [Voice input](docs/voice-input.md): dictation and its limits
20
- - [Styling](docs/styling.md): texts, languages, AI disclosure, custom CSS, `askdare('open' | 'configure')`, inline mode
21
- - [React](docs/react.md): the chat inside a page of your own app with `@boldare/askdare/react`: `getChatConfig`, `Root`, `DefaultChat`, hooks and primitives, tool cards (`toolRenderers`, `ToolResults`, `Link`), CSS resets, CSP, `add ui`
22
- - [Texts](docs/texts.md): every text key with its English and Polish default, plurals, adding a language, switching the chat's language on the page (`askdare('configure', { locale })`, `data-follow-lang`)
20
+ - [Styling](docs/styling.md): texts, languages, AI disclosure, custom CSS and the `data-ask-part` names, `askdare('open' | 'configure')`, inline mode
21
+ - [React](docs/react.md): the chat inside a page of your own app with `@boldare/askdare/react`: `getChatConfig`, `Root`, `DefaultChat`, hooks and primitives, tool cards (`toolRenderers`, `ToolResults`, `Link`), the AI notice in your own markup (`Disclosure`), the human check (`HumanCheck`), CSS resets, CSP, `add ui`
22
+ - [Texts](docs/texts.md): every text key with its default in each built-in language (en, cs, de, es, fr, it, pl), plurals, adding a language, switching the chat's language on the page (`askdare('configure', { locale })`, `data-follow-lang`)
23
23
  - [Themes](docs/themes.md): Halo, Aura, Sage and Care, tokens and variants
24
24
  - [Deployment](docs/deployment.md): Vercel, Heroku, proxies, shared limits
25
25
  - [Going public](docs/going-public.md): OpenAI project, secrets, limits, privacy checklist
26
+ - [Guardrails](docs/guardrails.md): opt-in OpenAI moderation (`moderation`), your own `onInput` and `onOutput` rules to allow, block or redact, answers held back while they are checked, `toolResults: 'untrusted'`
26
27
  - [Costs](docs/costs.md): the worst case under the default limits, and how to keep it bounded
27
28
  - [Observability](docs/observability.md): `onUsage` and `onError`, cost per turn, OpenTelemetry spans with `@boldare/askdare-otel`
28
29
  - [Chat events](docs/events.md): what the chat reports to the page, for analytics
29
30
  - [Answer ratings](docs/feedback.md): 👍/👎 with an optional comment, `onFeedback`, what the report holds
30
- - [Privacy](docs/privacy.md): what is stored where, for your privacy policy
31
- - [Support](docs/support.md): Node.js, Next.js, React, zod and TypeScript versions, browsers, sizes
31
+ - [Privacy](docs/privacy.md): what is stored where and sent to whom (OpenAI, its moderation endpoint, Cloudflare for the human check), for your privacy policy
32
+ - [Compliance](docs/compliance.md): AI Act disclosure (`widget.disclosure`, the `Disclosure` primitive), GDPR (DPA, retention, deletion), data residency, the resume token in inline mode, hosts other than Vercel and Heroku, no Edge runtime
33
+ - [Accessibility](docs/accessibility.md): the WCAG 2.2 AA conformance statement: scope, how it is tested, finished answers announced to screen readers, focus kept in a full-screen chat, known limitations
34
+ - [Support](docs/support.md): Node.js (22, 24 and 26), Next.js, React, zod and TypeScript versions, browsers, sizes
32
35
  - [Migrating from @boldare/openai-assistant](docs/migrating-from-openai-assistant.md): what maps to what
33
36
 
34
37
  ## Optional
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boldare/askdare",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Embeddable AI chatbot for Next.js, as a script-tag widget or React components, built on the official OpenAI SDK.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: askdare
3
- description: Add, configure or troubleshoot the @boldare/askdare AI chat in a Next.js app (defineBot, defineTool, createChatHandler, the widget script, the React chat inside a page, tool cards, your own page in the widget's iframe, themes, knowledge base, reply options, the chat's language, answer ratings, usage reports, deployment). Use when the project depends on @boldare/askdare or the user asks for a website chatbot built on it.
3
+ description: Add, configure or troubleshoot the @boldare/askdare AI chat in a Next.js app (defineBot, defineTool, createChatHandler, the widget script, the React chat inside a page, tool cards, your own page in the widget's iframe, themes, knowledge base, reply options, the chat's language, answer ratings, usage reports, guardrails and moderation, the Turnstile human check, the AI notice, accessibility, deployment). Use when the project depends on @boldare/askdare or the user asks for a website chatbot built on it.
4
4
  ---
5
5
 
6
6
  # askdare
@@ -17,13 +17,17 @@ description: Add, configure or troubleshoot the @boldare/askdare AI chat in a Ne
17
17
 
18
18
  ## Public API: use only this
19
19
 
20
- - `defineBot`, `defineTool`, `defineTheme` from `@boldare/askdare`; `createChatHandler` from `@boldare/askdare/next`, with its `onError`, `onUsage` and `onFeedback` options; `otelUsage()` from `@boldare/askdare-otel`.
20
+ - `defineBot`, `defineTool`, `defineTheme`, `turnstile` and `ERROR_CODES` from `@boldare/askdare`; `defineBot` returns a `BotHandle` (only `id` and `embedPath`): pass it to `createChatHandler`, `getChatConfig` and `getEmbedConfig`, and type it as `BotHandle` (or `BotDefinition` for the input), never as `Bot`; `createChatHandler` from `@boldare/askdare/next`, with its `onError`, `onUsage` and `onFeedback` options; `otelUsage()` from `@boldare/askdare-otel`.
21
21
  - On pages: `<script src="…/api/chat/widget.js?bot=<id>" async>` with `data-launcher="none"` or `data-mode="inline" data-target="…"`, and `askdare('open' | 'close' | 'toggle' | 'configure', …)`.
22
22
  - The chat's language on the page, for a bot with `locale: 'auto'`: `askdare('configure', { locale: 'pl' })`, or `data-follow-lang` on the script tag to follow `<html lang>`. The chat reloads in the new language and keeps the conversation; your `instructions` get it as `context.locale`. See `docs/texts.md`.
23
23
  - Reply options (clickable answers under the latest reply): `widget.replies: 'suggest'` lets the model suggest them; `defineTool({ replies: (result) => [...] })` derives them from a tool's result. See `docs/reply-options.md`.
24
24
  - The chat inside a page of the same Next.js app (React 19): `getChatConfig` from `@boldare/askdare/next` in a Server Component, then `Root`, `DefaultChat`, the hooks (`useChat`, `useChatState`, `useMessage`) and the primitives from `@boldare/askdare/react` (see `docs/react.md`). To change the default components, run `npx @boldare/askdare add ui`; don't copy them from `node_modules` by hand.
25
25
  - Tool cards: `defineTool({ ui: (result) => data })` picks what the visitor may see of a result (plain JSON, at most 8 KB; only that reaches the browser), and `Root`'s `toolRenderers={{ tool_name: Component }}` draws it, typed with `Chat.ToolRendererProps<typeof tool>` and `import type`. Render `data` as text and URLs through `Chat.Link`. See `docs/react.md#tool-cards`.
26
26
  - Your own page in the widget's iframe: `defineBot({ embedPath: '/askdare/support' })`; the page lives in its own route group and root layout, renders `<EmbedRoot config={getEmbedConfig({ bots, bot, searchParams })}>` from `@boldare/askdare/embed` with `DefaultChat` inside, and gets `embedPageHeaders({ bots, bot })` from `proxy.ts` (not `next.config.ts` headers, which are fixed at build). Check with `askdare doctor --origin <site>`. See `docs/embedding.md#your-own-page-in-the-iframe`.
27
+ - Guardrails, all opt-in in `defineBot` (see `docs/guardrails.md`): `moderation: { model, check?, categories?, message? }` runs OpenAI moderation on messages (`check: 'input'`, the default), answers (`'output'`) or both; `onInput(text, context)` and `onOutput(text, context)` return `{ action: 'allow' }`, `{ action: 'block', message? }` or `{ action: 'redact', text }`; `toolResults: 'untrusted'` marks tool results as third-party data. While answers are checked, they arrive whole at the end of the turn, and a conversation takes one turn at a time.
28
+ - Human check (see `docs/configuration.md#human-check`): `security: { humanVerifier: turnstile({ siteKey }) }`, with `TURNSTILE_SECRET_KEY` in the environment. A chat inside your page must allow `https://challenges.cloudflare.com` in its CSP, and a headless chat renders the `HumanCheck` primitive. `createChatHandler({ limits: { requireSharedStore: true } })` refuses to load without a shared store.
29
+ - The AI notice: on by default (`widget.disclosure`). In your own markup, or your own page in the iframe, render the `Disclosure` primitive; in development the console notes a chat without one.
30
+ - Built-in texts in en, cs, de, es, fr, it and pl; `widget.texts` overrides them per language (see `docs/texts.md`).
27
31
  - Styling: `widget.texts`, `widget.theme`, `widget.css` with `[data-ask-part="…"]` selectors and `--ask-*` tokens (see `docs/styling.md`).
28
32
 
29
33
  Never import from `@boldare/askdare/dist/…` or other internal paths.
@@ -43,4 +47,7 @@ Never import from `@boldare/askdare/dist/…` or other internal paths.
43
47
  - Reply options: at most 4, up to 80 characters each, plain text without links; anything else is dropped. A click only sends the option's text as the visitor's message, so write options the way a visitor would say them ("Cancel the order"), never as commands or IDs, and never treat a clicked option as more trusted than typed text.
44
48
  - More than one server instance (Vercel, several dynos) needs shared limits: `@boldare/askdare-upstash`.
45
49
  - Answer ratings (👍/👎) show only with `createChatHandler({ onFeedback })`; `widget.feedback: false` hides them for one bot. askdare stores no ratings: save the report in `onFeedback`. A rating's `comment` is visitor text: escape it wherever it is shown, and cover it in the privacy notice. See `docs/feedback.md`.
50
+ - Guardrail hooks must not throw to block: a hook that throws lets the text through (fail open) and logs one line. Moderation and hooks don't check attached files; keep `attachments` off where that matters. Never log the text a hook receives.
51
+ - Accessibility: keep `Messages` and its `announcement` part, and don't add your own live region for answers; screen readers hear each finished answer once (see `docs/accessibility.md`).
52
+ - Compliance and privacy: `docs/compliance.md` and `docs/privacy.md`. Name Cloudflare in the privacy notice when the human check is on, and OpenAI's moderation when `moderation` is.
46
53
  - Costs and tracing: `onUsage` (or `onUsage: otelUsage()` from `@boldare/askdare-otel`). Its reports hold pseudonyms and counts, never message text; don't add any. See `docs/observability.md`.