@boldare/askdare 0.4.0 → 0.5.1

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 (49) hide show
  1. package/CHANGELOG.md +54 -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-marked.js +883 -810
  13. package/dist/react.d.ts +24 -4
  14. package/dist/react.js +126 -18
  15. package/dist/root.js +170 -38
  16. package/dist/tool-results.d.ts +11 -1
  17. package/dist/ui/askdare.css +9 -1
  18. package/dist/ui/avatar.tsx +1 -1
  19. package/dist/ui/chat.tsx +1 -1
  20. package/dist/ui/confirm.tsx +1 -1
  21. package/dist/ui/context.ts +1 -1
  22. package/dist/ui/feedback.tsx +1 -1
  23. package/dist/ui/footer.tsx +3 -15
  24. package/dist/ui/header.tsx +1 -1
  25. package/dist/ui/icons.tsx +1 -1
  26. package/dist/ui/index.ts +1 -1
  27. package/dist/ui/message.tsx +1 -1
  28. package/dist/ui/panel.tsx +3 -1
  29. package/dist/ui/welcome.tsx +1 -1
  30. package/docs/accessibility.md +83 -0
  31. package/docs/cli.md +4 -3
  32. package/docs/compliance.md +160 -0
  33. package/docs/configuration.md +47 -2
  34. package/docs/costs.md +8 -1
  35. package/docs/custom-store.md +2 -0
  36. package/docs/embedding.md +2 -0
  37. package/docs/feedback.md +1 -1
  38. package/docs/going-public.md +15 -3
  39. package/docs/guardrails.md +128 -0
  40. package/docs/migrating-from-openai-assistant.md +1 -1
  41. package/docs/privacy.md +26 -2
  42. package/docs/react.md +7 -1
  43. package/docs/styling.md +2 -2
  44. package/docs/support.md +3 -3
  45. package/docs/texts.md +100 -96
  46. package/docs/troubleshooting.md +30 -3
  47. package/llms.txt +12 -9
  48. package/package.json +4 -4
  49. package/skills/askdare/SKILL.md +9 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # @boldare/askdare
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 87d0133: The `jose` dependency, which encrypts the resume token, is updated to 6.2.18.
8
+ - da8f8dc: Answers render more Markdown correctly: the bundled `marked` is updated to 18.2.1, with fixes for block quotes and lists with lazy lines, tabs, link destinations, bracket escapes in code spans, task-list markers and trailing blank lines in fenced code. `@boldare/askdare/react` grows by about 0.5 KB gzipped; its size budget is now 34 KB (ADR-0028).
9
+ - 5b84434: The `openai` dependency is updated to 7.62.0 (from 7.56.0). Nothing changes in how askdare calls the API.
10
+
11
+ ## 0.5.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 2be0e0a: Optional bot protection, both off by default; a bot that turns neither on works as in 0.4.
16
+
17
+ - **Human check with Cloudflare Turnstile:** `security: { humanVerifier: turnstile({ siteKey }) }` in `defineBot`, with the secret key in `TURNSTILE_SECRET_KEY`. The chat shows the Turnstile widget when it needs a new session, and `/session` checks the token with Cloudflare; renewing a live session needs no new check for 24 hours after the visitor passed one. For that bot only, the iframe's Content Security Policy allows `https://challenges.cloudflare.com` in `script-src` and `frame-src`. A chat inside your page must allow the same origin in your page's policy, and a headless chat renders the new `HumanCheck` primitive. To check tokens another way, implement the `HumanVerifier` type.
18
+ - **`limits.requireSharedStore`** in `createChatHandler`: with `true`, the route refuses to load unless `limits.store` is shared, instead of only warning in production.
19
+
20
+ New texts `humanCheck.label` and `error.humanCheck`, a `human-check` part, and `state.humanCheck` in the React hooks.
21
+ - 1b5c112: New `Disclosure` primitive in `@boldare/askdare/react`: the AI notice (EU AI Act, art. 50) for your own markup and for your own page in the widget's iframe. It shows `disclosure.text` with the `widget.disclosure.privacyUrl` link, takes children to replace the text, and renders nothing with `disclosure: false`. The default look now uses it, with the same markup as before.
22
+
23
+ In development, `Root` and `EmbedRoot` note once in the console when the chat rendered without a `Disclosure` while the bot keeps the notice on; `widget.disclosure: false` silences it. `askdare doctor` lists bots with `disclosure: false` as information, not a failure. Nothing changes for existing bots.
24
+ - 1f19a17: Guardrails, all opt-in and set in `defineBot` (ADR-0019). A bot that sets none of them behaves exactly as before.
25
+
26
+ - `moderation: { model, check?, categories?, message? }` runs OpenAI moderation on visitors' messages (`check: 'input'`, the default), on answers (`'output'`) or both. You choose the moderation model, which categories block (default: any flagged one) and the text visitors see. Each checked message adds one call to OpenAI's moderation endpoint.
27
+ - `onInput(text, context)` and `onOutput(text, context)` return `{ action: 'allow' }` (or `undefined`), `{ action: 'block', message? }` or `{ action: 'redact', text }`. A hook that throws lets the text through and logs one line naming the hook.
28
+ - While answers are checked (`onOutput`, or moderation of output), they are held back on the server until complete, then sent whole, replaced or blocked; reasoning and tool status still stream. A blocked answer never reaches the browser, and a replaced one comes without its tool cards and reply options. For these bots the history shows an answer only once its check passed, and a conversation takes one turn at a time (a second message meanwhile gets `rate_limited`).
29
+ - Blocked turns end with the existing `content_blocked` error, with your text or the translated default. Nothing blocked or redacted is logged as content. Attached files are not checked.
30
+ - `toolResults: 'untrusted'` hands tool results to the model wrapped as third-party data that it must not follow as instructions. Recommended for tools that return text from outside your control.
31
+
32
+ New exported types: `GuardrailOptions`, `ModerationConfig`, `GuardHook`, `GuardVerdict` and `GuardContext`. See `docs/guardrails.md`.
33
+ - 1b94b92: Built-in texts in Czech, German, Spanish, French and Italian, next to English and Polish. `widget.locale` set to one of these languages, or `'auto'` on a page or browser in one of them, now shows the chat and the launcher in that language with no `widget.texts` of your own. Your overrides still win. Other languages keep showing English.
34
+ - 5aecb96: Public API clean-up before 1.0 (ADR-0020, ADR-0021).
35
+
36
+ - **`defineBot` now returns a `BotHandle`**, which exposes only `id` and `embedPath`. Pass it to `createChatHandler`, `getChatConfig` and `getEmbedConfig` as before. The resolved `Bot` type, with its filled-in defaults, is no longer exported. If you annotated a variable as `Bot`, use `BotHandle` (or `BotDefinition` for the input). Passing an object that didn't come from `defineBot` now throws a clear `TypeError`.
37
+ - **`ERROR_CODES` and `ErrorCode` are exported** from `@boldare/askdare`, so you can switch on the `code` that `onError` and the chat report.
38
+ - Node.js 26 joins the support matrix.
39
+ - `zod` stays a required peer: `defineBot` validates every definition with it.
40
+
41
+ Type-only removals can't warn at runtime a minor ahead, so this changeset names the replacements instead.
42
+
43
+ ### Patch Changes
44
+
45
+ - 7f962ab: Screen readers now hear a finished answer once, as its rendered text. The conversation (`Messages`) is still a `log` but no longer a live region, since text growing inside a message was read in fragments or not at all; a visually hidden `status` next to it (`data-ask-part="announcement"`) announces each answer when it ends. Answers restored after a reload aren't read out. New guide, `docs/accessibility.md`: the dated WCAG 2.2 AA conformance statement, with its scope, method, manual review and known limitations.
46
+ - 8744972: New guide, `docs/compliance.md`: what the AI Act, the GDPR and the European Accessibility Act ask of a website chatbot, what askdare does about each, and the decisions left to you. It covers the AI disclosure, OpenAI's DPA, retention and deletion, `safety_identifier`, OpenAI's data residency (which doesn't cover the Conversations API askdare uses), the resume token in a chat inside your page, and hosts other than Vercel and Heroku (Docker, `next start`, OpenNext; no Edge runtime). It isn't legal advice.
47
+ - b5f3c44: A conversation that outgrows the model's context window now ends with "This conversation is too long. Please start a new one." (`invalid_input`, key `error.conversationTooLong`) instead of a generic "temporarily unavailable" error, should OpenAI ever refuse it. askdare keeps sending the deprecated `truncation: 'auto'` until OpenAI announces a shutdown date, so long conversations keep working as before.
48
+ - 6aacbb8: `askdare doctor` warns when OpenAI has announced a shutdown date for a bot's model or its transcription model, with the date from the OpenAI API and a link to OpenAI's deprecations page for the replacement.
49
+ - 5d745bf: A chat that fills the screen (on a phone, or a desktop page zoomed to 400%) keeps keyboard focus until it is closed, instead of letting it move to the page hidden behind it (WCAG 2.4.11).
50
+ - 08a1b01: A bot's `widget.css` can no longer reach the host page when the chat is inside a page. A stray `}` used to close the `@scope` block early, so a typo like `a { color: red } } body { display: none }` applied `body { display: none }` to the whole page. Stray closing braces are now dropped, and unclosed blocks or strings are closed, so every rule stays scoped to the chat.
51
+ - 0c0ccda: Server logs no longer risk carrying what a visitor wrote. When OpenAI rejects a request with a message that quotes the value it refused, or any other failure reaches the default error log (no `onError` set), quoted values longer than 32 characters are replaced, API keys are cut to their prefix and the message is capped at 300 characters. Status, error code, request ID and stack frames stay, so the logs remain useful for debugging.
52
+ - fe8f7d8: Docs: releases are now tested on an iPhone viewport in WebKit (Safari's engine) automatically, and no longer wait on manual checks in Safari on iOS or with screen readers. The accessibility statement says so: screen readers are not tested by hand, and what they rely on is checked by the automated tests.
53
+ - c8ed689: Docs for 0.5: `privacy.md` covers the moderation calls to OpenAI and Cloudflare as a processor for the human check, `troubleshooting.md` covers guardrail blocks, the one-turn-at-a-time hold and a failing human check, `cli.md` lists doctor's note about the AI notice, `styling.md` lists the `announcement` part, and the package READMEs list what is new in 0.5 and `limits.requireSharedStore`.
54
+ - a190bcd: Streamed answers stay smooth however long they get: `Markdown` now re-lexes and re-renders only the last blocks of a message on each delta, instead of the whole answer. Sanitizing is unchanged.
55
+ - 8fba8ee: Bots with `replies: 'suggest'` no longer write their answer twice. Current models mark an answer written before the `suggest_replies` call as commentary, and askdare took that as an unfinished turn and asked the model again, which repeated the answer. Text followed only by reply options now ends the turn as the answer, and the history shows it once.
56
+
3
57
  ## 0.4.0
4
58
 
5
59
  ### Minor Changes
package/README.md CHANGED
@@ -38,9 +38,19 @@ export const bots = [
38
38
 
39
39
  ## What you get
40
40
 
41
- [![What it does: answers from your documents with citations, your own tools, images and PDFs, voice input, secure by default, the chat inside your own page with React, thumbs-up and thumbs-down ratings of answers, observability with OpenTelemetry, and chat events for analytics. Also clickable answers suggested by the model, reply options from your tools, switching the chat's language from the page, and a one-click deploy. New in 0.4: tool cards, drawn by your own React components, your own page inside the widget, and texts per language. No database.](https://raw.githubusercontent.com/boldare/askdare/main/.github/assets/askdare-features.png)](https://askdare.vercel.app/#features)
41
+ [![What it does: answers from your documents with citations, your own tools, images and PDFs, voice input, secure by default, the chat inside your own page with React, thumbs-up and thumbs-down ratings of answers, observability with OpenTelemetry, and chat events for analytics. Also clickable answers suggested by the model, reply options from your tools, switching the chat's language from the page, a one-click deploy, tool cards drawn by your own React components, your own page inside the widget, and texts per language. New in 0.5: guardrails with OpenAI moderation and your own rules, a human check with Cloudflare Turnstile, seven built-in languages, and WCAG 2.2 AA. No database.](https://raw.githubusercontent.com/boldare/askdare/main/.github/assets/askdare-features.png)](https://askdare.vercel.app/#features)
42
+
43
+ [Knowledge base](https://askdare.vercel.app/docs/knowledge-base) · [Tools](https://askdare.vercel.app/docs/tools) · [Tool cards](https://askdare.vercel.app/docs/react#tool-cards) · [Reply options](https://askdare.vercel.app/docs/reply-options) · [Attachments](https://askdare.vercel.app/docs/attachments) · [Voice input](https://askdare.vercel.app/docs/voice-input) · [The chat inside your page (React)](https://askdare.vercel.app/docs/react) · [Your own page in the widget](https://askdare.vercel.app/docs/embedding#your-own-page-in-the-iframe) · [Answer ratings](https://askdare.vercel.app/docs/feedback) · [Guardrails](https://askdare.vercel.app/docs/guardrails) · [Accessibility](https://askdare.vercel.app/docs/accessibility) · [Security](https://github.com/boldare/askdare/blob/main/THREAT_MODEL.md)
44
+
45
+ **New in 0.5:**
46
+
47
+ - **Guardrails**, all opt-in: OpenAI moderation of messages and answers, your own `onInput` and `onOutput` rules to block or redact, and tool results marked as untrusted. See [Guardrails](https://askdare.vercel.app/docs/guardrails).
48
+ - **Bot protection**: an optional human check with Cloudflare Turnstile (`security.humanVerifier`), and `limits.requireSharedStore` to refuse a deployment without shared limits. See [Configuration](https://askdare.vercel.app/docs/configuration#human-check).
49
+ - **Seven languages built in**: Czech, German, Spanish, French and Italian join English and Polish. See [Texts](https://askdare.vercel.app/docs/texts).
50
+ - **WCAG 2.2 AA**: finished answers are read out once, a full-screen chat keeps the focus, and a dated [accessibility statement](https://askdare.vercel.app/docs/accessibility).
51
+ - **Compliance**: the `Disclosure` primitive for the AI notice in your own markup, and a [guide](https://askdare.vercel.app/docs/compliance) to what the AI Act, the GDPR and the European Accessibility Act ask of a website chatbot.
52
+ - **Also**: `doctor` warns about model shutdown dates, smoother streaming of long answers, error logs without visitor text, and a clear error when a conversation outgrows the model's context. `defineBot` returns a `BotHandle`, `ERROR_CODES` is exported, and Node.js 26 is supported. See the [changelog](https://github.com/boldare/askdare/blob/main/packages/askdare/CHANGELOG.md).
42
53
 
43
- [Knowledge base](https://askdare.vercel.app/docs/knowledge-base) · [Tools](https://askdare.vercel.app/docs/tools) · [Tool cards](https://askdare.vercel.app/docs/react#tool-cards) · [Reply options](https://askdare.vercel.app/docs/reply-options) · [Attachments](https://askdare.vercel.app/docs/attachments) · [Voice input](https://askdare.vercel.app/docs/voice-input) · [The chat inside your page (React)](https://askdare.vercel.app/docs/react) · [Your own page in the widget](https://askdare.vercel.app/docs/embedding#your-own-page-in-the-iframe) · [Answer ratings](https://askdare.vercel.app/docs/feedback) · [Security](https://github.com/boldare/askdare/blob/main/THREAT_MODEL.md)
44
54
 
45
55
  ## Themes
46
56
 
@@ -54,7 +64,7 @@ The guides are on [askdare.vercel.app/docs](https://askdare.vercel.app/docs), wi
54
64
 
55
65
  - **Start:** [Getting started](https://askdare.vercel.app/docs/getting-started) · [Embedding the chat](https://askdare.vercel.app/docs/embedding) · [Command line](https://askdare.vercel.app/docs/cli)
56
66
  - **Look and language:** [Themes](https://askdare.vercel.app/docs/themes) · [Styling](https://askdare.vercel.app/docs/styling) · [Texts](https://askdare.vercel.app/docs/texts) · [The chat inside your page (React)](https://askdare.vercel.app/docs/react)
57
- - **Going live:** [Deployment](https://askdare.vercel.app/docs/deployment) · [Going-public checklist](https://askdare.vercel.app/docs/going-public) · [Costs](https://askdare.vercel.app/docs/costs) · [Observability](https://askdare.vercel.app/docs/observability) · [Chat events](https://askdare.vercel.app/docs/events) · [Answer ratings](https://askdare.vercel.app/docs/feedback) · [Privacy](https://askdare.vercel.app/docs/privacy)
67
+ - **Going live:** [Deployment](https://askdare.vercel.app/docs/deployment) · [Going-public checklist](https://askdare.vercel.app/docs/going-public) · [Guardrails](https://askdare.vercel.app/docs/guardrails) · [Costs](https://askdare.vercel.app/docs/costs) · [Observability](https://askdare.vercel.app/docs/observability) · [Chat events](https://askdare.vercel.app/docs/events) · [Answer ratings](https://askdare.vercel.app/docs/feedback) · [Privacy](https://askdare.vercel.app/docs/privacy) · [Compliance](https://askdare.vercel.app/docs/compliance) · [Accessibility](https://askdare.vercel.app/docs/accessibility)
58
68
  - **Reference:** [Configuration](https://askdare.vercel.app/docs/configuration) · [Troubleshooting](https://askdare.vercel.app/docs/troubleshooting) · [Support matrix](https://askdare.vercel.app/docs/support)
59
69
  - **AI coding agents:** `llms.txt` and the `askdare` skill ship in the package ([how to use them](https://askdare.vercel.app/docs/getting-started#working-with-an-ai-coding-agent))
60
70
 
@@ -67,7 +77,7 @@ The guides are on [askdare.vercel.app/docs](https://askdare.vercel.app/docs), wi
67
77
 
68
78
  ## Requirements
69
79
 
70
- Node.js 22 or later, Next.js 16 with the App Router on the Node.js runtime, React 19 and zod 4.1 or later.
80
+ Node.js 22, 24 or 26, Next.js 16 with the App Router on the Node.js runtime, React 19 and zod 4.1 or later.
71
81
 
72
82
  ## License
73
83
 
package/dist/cli.js CHANGED
@@ -257,6 +257,7 @@ const doctorReportSchema = z.object({
257
257
  id: z.string().max(48),
258
258
  checks: z.array(check).max(20),
259
259
  turnTimeoutMs: z.number().int().positive().optional(),
260
+ disclosure: z.boolean().optional(),
260
261
  embed: z.object({
261
262
  path: z.string().refine(isEmbedPath),
262
263
  allowedOrigins: z.array(z.string().max(300)).max(50),
@@ -533,10 +534,13 @@ async function createTokenService(options) {
533
534
  });
534
535
  }
535
536
  return {
536
- issueAccess: (botId, visitorId, identity) => issue(ACCESS_TYP, botId, visitorId, identity ? Math.max(1, Math.min(accessTtl, identity.expiresAt - now())) : accessTtl, identity ? {
537
- idn: { ...identity.identity },
538
- ixp: identity.expiresAt
539
- } : {}),
537
+ issueAccess: (botId, visitorId, identity, humanCheckedAt) => issue(ACCESS_TYP, botId, visitorId, identity ? Math.max(1, Math.min(accessTtl, identity.expiresAt - now())) : accessTtl, {
538
+ ...identity ? {
539
+ idn: { ...identity.identity },
540
+ ixp: identity.expiresAt
541
+ } : {},
542
+ ...humanCheckedAt === void 0 ? {} : { hv: humanCheckedAt }
543
+ }),
540
544
  async verifyAccess(token, botId) {
541
545
  try {
542
546
  const { payload } = await verify(token, ACCESS_TYP, botId);
@@ -554,9 +558,11 @@ async function createTokenService(options) {
554
558
  try {
555
559
  const { payload } = await verify(token, ACCESS_TYP, botId, RENEWAL_GRACE_SECONDS);
556
560
  if (typeof payload.sub !== "string" || !VISITOR_ID.test(payload.sub)) throw new AskdareError("unauthorized");
561
+ const { hv } = payload;
557
562
  return {
558
563
  visitorId: payload.sub,
559
- identity: identityOf(payload, now())
564
+ identity: identityOf(payload, now()),
565
+ ...typeof hv === "number" && Number.isFinite(hv) ? { humanCheckedAt: hv } : {}
560
566
  };
561
567
  } catch (error) {
562
568
  throw new AskdareError("unauthorized", { cause: error });
@@ -655,6 +661,11 @@ const fail = (title, fix) => ({
655
661
  title,
656
662
  fix
657
663
  });
664
+ const info = (title, fix) => ({
665
+ status: "info",
666
+ title,
667
+ fix
668
+ });
658
669
  const PROXY_FIX = "Exclude askdare's routes in proxy.ts, e.g. matcher: ['/((?!api/chat|_next/static|_next/image).*)'].";
659
670
  function versions(project) {
660
671
  const checks = [];
@@ -928,13 +939,15 @@ async function live(options, project, env) {
928
939
  checks: [
929
940
  ...bot.checks,
930
941
  ...await headers(fetcher, base, bot.id, options.origin, bot.embed),
931
- ...timeout(bot, routeSeconds)
942
+ ...timeout(bot, routeSeconds),
943
+ ...bot.disclosure === false ? [info("The AI notice is off (widget.disclosure: false).", "Fine when your page already tells visitors they are talking to an AI (EU AI Act, art. 50).")] : []
932
944
  ]
933
945
  });
934
946
  return sections;
935
947
  }
936
948
  const MARK = {
937
949
  ok: "✓",
950
+ info: "i",
938
951
  warn: "!",
939
952
  fail: "✗"
940
953
  };