@boldare/askdare 0.3.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 (52) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +14 -4
  3. package/dist/cli.js +111 -26
  4. package/dist/define-tool.js +1006 -8
  5. package/dist/embed.d.ts +19 -0
  6. package/dist/embed.js +250 -0
  7. package/dist/{store.d.ts → events.d.ts} +163 -54
  8. package/dist/index.d.ts +28 -2
  9. package/dist/index.js +74 -158
  10. package/dist/next.d.ts +70 -9
  11. package/dist/next.js +767 -169
  12. package/dist/react-marked.js +648 -624
  13. package/dist/react.d.ts +63 -77
  14. package/dist/react.js +148 -1854
  15. package/dist/root.js +2254 -0
  16. package/dist/tool-results.d.ts +140 -0
  17. package/dist/ui/askdare.css +21 -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 +6 -4
  28. package/dist/ui/panel.tsx +17 -6
  29. package/dist/ui/welcome.tsx +1 -1
  30. package/docs/accessibility.md +83 -0
  31. package/docs/cli.md +5 -3
  32. package/docs/compliance.md +160 -0
  33. package/docs/configuration.md +58 -2
  34. package/docs/costs.md +8 -1
  35. package/docs/custom-store.md +2 -0
  36. package/docs/embedding.md +104 -0
  37. package/docs/events.md +1 -1
  38. package/docs/feedback.md +1 -1
  39. package/docs/going-public.md +15 -3
  40. package/docs/guardrails.md +128 -0
  41. package/docs/migrating-from-openai-assistant.md +1 -1
  42. package/docs/privacy.md +27 -3
  43. package/docs/protocol.md +15 -1
  44. package/docs/react.md +57 -3
  45. package/docs/styling.md +4 -3
  46. package/docs/support.md +3 -3
  47. package/docs/texts.md +127 -98
  48. package/docs/tools.md +20 -0
  49. package/docs/troubleshooting.md +30 -3
  50. package/llms.txt +14 -11
  51. package/package.json +10 -6
  52. package/skills/askdare/SKILL.md +12 -2
@@ -0,0 +1,160 @@
1
+ # Compliance
2
+
3
+ This page lists what the law asks of a chatbot on a public website, what askdare does about each point, and which decisions stay with you. It names the laws and cites them, but **it isn't legal advice**. Whether a rule applies to you, and whether askdare's defaults are enough, depends on your role, your site and your users. Check with your legal advisers.
4
+
5
+ Legal texts and OpenAI's terms were checked on 2026-11-21 against the sources at the [end of this page](#sources). Both change: check the sources again before you rely on a date or a limit.
6
+
7
+ ## At a glance
8
+
9
+ | Topic | What askdare does | What you decide |
10
+ | --- | --- | --- |
11
+ | [Telling visitors they talk to an AI](#1-telling-visitors-they-talk-to-an-ai) (AI Act, art. 50(1)) | A note under the message field, on by default | Keep it, word it, or turn it off when your page already says so |
12
+ | [Personal data](#2-personal-data-gdpr) (GDPR) | Stores nothing on your server but rate-limit counters; sends a pseudonym, not an identity, to OpenAI; lets visitors delete their conversation | Your privacy notice, the DPA with OpenAI, a retention policy for conversations |
13
+ | [Data residency](#3-data-residency) | Uses OpenAI's global endpoints | Whether OpenAI's regional options are enough, or you wait for own storage (0.6) |
14
+ | [The conversation handle in the browser](#4-the-conversation-handle-in-the-browser) | Keeps it in the widget's iframe | Whether to show the chat inside your own pages |
15
+ | [Accessibility](#5-accessibility) (European Accessibility Act) | Targets WCAG 2.2 AA | Your site's own conformance |
16
+ | [Moderation and guardrails](#6-moderation-and-guardrails) | Opt-in OpenAI moderation, hooks to block or redact messages and answers, untrusted tool results | Which of them your bot needs, and what blocked visitors see |
17
+ | [Bot protection](#7-bot-protection) | Rate limits and daily budgets by default; an optional human check with Cloudflare Turnstile | Whether your chat needs the human check, and naming Cloudflare in your privacy notice if it does |
18
+ | [Hosting](#8-hosting-outside-vercel-and-heroku) | Supports the Node.js runtime only | Where it runs, and that host's logs |
19
+
20
+ ## 1. Telling visitors they talk to an AI
21
+
22
+ **The rule.** Under Article 50(1) of the AI Act, AI systems that interact directly with people must be designed so that those people are informed they are interacting with an AI system, unless that is obvious to a reasonably well-informed person in the context. Article 50(5) says the information must be clear and distinguishable, given at the latest at the first interaction, and accessible. Article 50 applies from 2 August 2026 (Article 113). The Digital Omnibus on AI, Regulation (EU) 2026/1744, moved the high-risk rules to 2 December 2027 and 2 August 2028; it didn't change Article 50(1) or its date.
23
+
24
+ The duty in Article 50(1) is the provider's: whoever develops the system, or has it developed, and puts it into service under its own name. When you put a bot on your site with your instructions, your legal advisers will tell you whether that is you.
25
+
26
+ **What askdare does.** By default, the chat shows "You’re chatting with an AI assistant. It can make mistakes." under the message field, before the visitor writes anything.
27
+
28
+ ```ts
29
+ defineBot({
30
+ // …
31
+ widget: {
32
+ disclosure: { privacyUrl: '/privacy' }, // adds a "Privacy policy" link
33
+ },
34
+ });
35
+ ```
36
+
37
+ - You can change the wording with `widget.texts` (`disclosure.text`, `disclosure.privacy`). See [Styling](styling.md#1-configuration) and [Texts](texts.md).
38
+ - `disclosure: false` hides it. Do that only when your page already tells visitors they are talking to an AI.
39
+ - **If you build your own markup** with the primitives of `@boldare/askdare/react` ([React](react.md#your-own-markup)), or show your own page in the widget's iframe ([Embedding](embedding.md#your-own-page-in-the-iframe)), place it with the `Disclosure` primitive, which follows the same `widget.disclosure` setting and texts. In development, `Root` and `EmbedRoot` note once in the console when the chat rendered without a `Disclosure`, and `askdare doctor` lists each bot with `disclosure: false` as information, not a failure. Neither forces the notice on you: `disclosure: false` silences both.
40
+
41
+ **Marking of generated content.** Article 50(2) asks providers of systems that generate synthetic text, images, audio or video to mark the outputs in a machine-readable format. askdare doesn't add such marks to answers. Systems on the market before 2 August 2026 have until 2 December 2026 (Article 111(4), added by the Digital Omnibus). Whether Article 50(2) covers a chat's answers, and who carries it, is a question for your legal advisers; the codes of practice under Article 50(7) are where the practice is being worked out.
42
+
43
+ ## 2. Personal data (GDPR)
44
+
45
+ [Privacy](privacy.md) lists every piece of data the chat handles, where it goes and how long it stays. This section covers the decisions it leaves to you.
46
+
47
+ ### Roles and the DPA
48
+
49
+ - For the chat on your site, you decide why and how visitors' data is processed, so you are usually the controller. OpenAI processes it on your behalf, as a processor (GDPR, Article 28).
50
+ - OpenAI's [Data Processing Addendum](https://openai.com/policies/data-processing-addendum/) covers API customers. For customers in the EEA or Switzerland the contracting party is OpenAI Ireland Ltd. Transfers out of the EEA rely on the EU standard contractual clauses or an adequacy decision (Articles 45 and 46). Make sure it applies to the OpenAI organization whose key the app uses.
51
+ - Upstash, if you use `@boldare/askdare-upstash`, and your hosting provider process data too. See [Subprocessors](privacy.md#subprocessors).
52
+
53
+ ### Retention and deletion
54
+
55
+ Storage limitation (Article 5(1)(e)) means keeping data no longer than you need it. Here is what lasts how long:
56
+
57
+ | What | Kept | How it ends |
58
+ | --- | --- | --- |
59
+ | Conversations (messages, answers, page context, tool calls and results) | Until deleted | The visitor's "Start a new conversation", which deletes it at OpenAI. Nothing else deletes it |
60
+ | Stored model responses | 30 days by default, according to OpenAI | OpenAI deletes them |
61
+ | Abuse-monitoring logs at OpenAI | Up to 30 days, longer where the law requires it | OpenAI deletes them |
62
+ | Uploaded images and PDFs | 30 days | They expire, or are deleted with their conversation |
63
+ | Rate-limit counters with IP addresses | Up to 2 days | They expire |
64
+
65
+ - **Conversations outlive the browser's handle.** When the handle expires after 30 days, or the visitor clears the browser, the conversation stays in your OpenAI project. askdare keeps no list of conversations, and OpenAI's API can't list them, so askdare has no tool to find or delete one person's conversation later (right to erasure, Article 17). Decide how you will answer such a request, and say in your notice how visitors delete a conversation themselves.
66
+ - **Zero Data Retention isn't available.** OpenAI lists the Conversations API as not eligible, and askdare needs it ([ADR-0003](https://github.com/boldare/askdare/blob/main/docs/adr/0003-conversation-state.md)).
67
+ - Own storage, planned for 0.6, will let you keep conversations in your database and set their retention yourself.
68
+
69
+ ### `safety_identifier`
70
+
71
+ Every model request carries a `safety_identifier`, which OpenAI uses to trace abuse to one end user instead of your whole project. It is an HMAC of the random visitor ID, or of your user ID for a [signed-in visitor](identity.md), keyed with a secret derived from `CHAT_SECRET`. It holds no name, email or IP address. It is still a pseudonym, not anonymous data: with the secret, it can be linked back. See [Privacy](privacy.md#safety_identifier).
72
+
73
+ ### Your privacy notice
74
+
75
+ Visitors must be told who processes their data, for what, and for how long (Article 13). Work through [the checklist in Privacy](privacy.md#for-your-privacy-notice), and link the notice from the AI note with `widget.disclosure.privacyUrl`.
76
+
77
+ ### Storage in the visitor's browser
78
+
79
+ The chat writes one `localStorage` entry after the visitor's first message, and a second one when they rate an answer. It sets no cookies. Whether these need consent under Article 5(3) of the ePrivacy Directive, which exempts storage strictly necessary for a service the user asked for, is your call: [Consent banners](privacy.md#consent-banners) lists the facts that matter.
80
+
81
+ ## 3. Data residency
82
+
83
+ OpenAI offers [data residency](https://developers.openai.com/api/docs/guides/data-residency) per project, in several regions, Europe (EEA and Switzerland) among them:
84
+
85
+ - It is available to eligible organizations after contacting OpenAI's sales team. A project's region is chosen when the project is created and can't be changed later.
86
+ - Requests go to a regional domain, such as `eu.api.openai.com`.
87
+ - Models released on or after 5 March 2026 cost 10% more on data residency endpoints.
88
+ - It covers Customer Content at rest for the endpoints OpenAI lists, and processing where the region supports it. System data, such as account and usage data, may still be stored and processed elsewhere.
89
+
90
+ **What that means for askdare.** askdare stores conversations with OpenAI's Conversations API (`/v1/conversations`), and OpenAI's list of endpoints eligible for data residency doesn't include it. A residency project therefore doesn't keep askdare's conversations in your region. askdare also uses OpenAI's global endpoint and isn't tested against regional ones.
91
+
92
+ If you need conversations stored in a given region, wait for own storage in 0.6: conversations kept in your own database, with only model requests going to OpenAI. The [roadmap](https://github.com/boldare/askdare/blob/main/ROADMAP.md) has the details.
93
+
94
+ ## 4. The conversation handle in the browser
95
+
96
+ To show a conversation again after a reload, the chat keeps a resume token in `localStorage`. It is encrypted, the browser can't read what's inside, and it works for 30 days after the last answer. Whoever holds it can continue that conversation and see its history. A signed-in visitor's conversation also needs that user's identity token.
97
+
98
+ Where it sits decides who can read it:
99
+
100
+ | How the chat is shown | Where the token sits | Who else can read it |
101
+ | --- | --- | --- |
102
+ | The script-tag widget, and your own page in its iframe | The iframe's storage, on your askdare app's origin | No script of the host site: the browser keeps origins apart, and the iframe's strict Content Security Policy keeps foreign scripts out of the chat |
103
+ | The chat inside your page (`Root`, `DefaultChat` from `@boldare/askdare/react`) | Your page's own storage, next to your other entries | Every script on that page, including an XSS on your app, tag managers and third-party tags. It can also read the conversation on screen and, for signed-in visitors, the identity token in the page |
104
+
105
+ An attacker who copies the token can continue the conversation from anywhere and read it, until the token expires or the visitor starts a new conversation. This is the trade-off of a chat inside your page: no iframe between your page's scripts and the chat. It is in the [threat model](https://github.com/boldare/askdare/blob/main/THREAT_MODEL.md) as T3 and T23.
106
+
107
+ - On pages that run scripts you don't fully trust (ads, tag managers with third-party tags), use the widget.
108
+ - Give pages with the chat inside them a strict Content Security Policy ([React](react.md#content-security-policy)).
109
+ - If you suspect a leak, rotate `CHAT_SECRET` without `CHAT_SECRET_PREVIOUS`: every resume token stops working at once, and visitors start new conversations ([Rotating secrets](privacy.md#rotating-secrets)).
110
+ - Mention the entry in your privacy notice either way.
111
+
112
+ ## 5. Accessibility
113
+
114
+ The [European Accessibility Act](https://eur-lex.europa.eu/eli/dir/2019/882/oj/eng) (Directive (EU) 2019/882) applies from 28 June 2025. Among other services, it covers e-commerce services offered to consumers; microenterprises that provide services are exempt (Article 4(5)). The harmonised standard, ETSI EN 301 549, moved to WCAG 2.2 in version V4.1.1 (2026-09).
115
+
116
+ askdare's widget and default skin target WCAG 2.2 AA, and every change runs axe with the WCAG 2.2 AA rules in Chromium, Firefox and WebKit and on a phone viewport ([Support](support.md)). The dated conformance statement, with its scope, method, the manual review and the known limitations, is [Accessibility](accessibility.md). If you build your own markup or restyle the chat, its accessibility is yours to check.
117
+
118
+ ## 6. Moderation and guardrails
119
+
120
+ OpenAI's own safety systems apply to every bot. On top of them, askdare offers three server-side controls, all off by default ([ADR-0019](https://github.com/boldare/askdare/blob/main/docs/adr/0019-compliance-and-guardrails.md)):
121
+ - **`moderation`:** OpenAI moderation of visitors' messages, of answers, or both, with the categories that block and the text visitors see as options.
122
+ - **`onInput` and `onOutput`:** your own rules, which allow, block or redact a message before the model sees it, or an answer before the visitor does. While answers are checked, they are held back until complete, so a blocked one never reaches the browser.
123
+ - **`toolResults: 'untrusted'`:** tool results reach the model marked as third-party data, which hardens tools that return text from outside your control against prompt injection.
124
+
125
+ A blocked turn ends with the `content_blocked` error, and nothing blocked or redacted is logged as content. Which controls a bot needs, and how strict they are, is your decision: see [Guardrails](guardrails.md).
126
+
127
+ ## 7. Bot protection
128
+
129
+ By default, rate limits and daily token budgets bound what an abuser can spend ([Going public](going-public.md#3-bot-configuration), [Costs](costs.md)). Two options make that stricter, and both are off until you turn them on ([ADR-0019](https://github.com/boldare/askdare/blob/main/docs/adr/0019-compliance-and-guardrails.md)):
130
+
131
+ - **A human check.** With `security.humanVerifier: turnstile({ siteKey })`, visitors pass Cloudflare Turnstile before a chat session starts, and the server checks the token with Cloudflare ([Configuration](configuration.md#human-check)). Turnstile runs Cloudflare's script in the chat, with the chat's access to the page it runs in (the widget's iframe, or your own page for a chat inside it), and sends Cloudflare data about the visitor's browser, including the IP address, so Cloudflare becomes a processor to name in your privacy notice. Anonymous visitors meet the check at their first action (a message, an upload, or loading a stored conversation); on a page that signs visitors in with `askdare('identify')`, the check shows as the chat loads. Whether the check needs consent where you operate, for example under the ePrivacy rules on reading from a visitor's device, is for your legal advisers. askdare never sends Cloudflare the conversation or the visitor's identity.
132
+ - **Shared counters required.** With `limits: { requireSharedStore: true }`, the route refuses to start without a shared store, so limits can't silently become per instance ([Custom rate-limit store](custom-store.md#the-shared-flag)).
133
+
134
+ ## 8. Hosting outside Vercel and Heroku
135
+
136
+ askdare is tested on Vercel and Heroku. Other hosts that run a Next.js app on Node.js should work, but aren't tested ([Support](support.md)). Whatever the host, it receives every request, with the visitor's IP address, and keeps logs by its own settings: name it in your privacy notice.
137
+
138
+ **What the host has to provide:**
139
+
140
+ - **The Node.js runtime,** Node.js 22 or 24.
141
+ - **Streaming without buffering.** Answers arrive as `text/event-stream`; a proxy that buffers them delivers each answer at once at the end. askdare sends `X-Accel-Buffering: no` for nginx.
142
+ - **Long requests.** An answer can take up to the bot's `limits.turnTimeoutMs`, 120 seconds by default. The host and every proxy in front of it must keep the connection open that long. askdare sends a byte every 15 seconds, so idle timeouts above that are enough.
143
+ - **A proxy that sets `X-Forwarded-For`.** Never expose `next start` directly to the internet: clients could then choose their own IP and per-IP limits stop working. Set `limits.trustProxy` to the number of proxies in front of the app ([Deployment](deployment.md#behind-another-proxy-or-cdn)).
144
+ - **A shared store for limits** when more than one instance serves traffic ([Going public](going-public.md#4-rate-limits-across-instances)).
145
+
146
+ **Docker or a VM with `next start`.** Run `next build` and `next start` (or the standalone output) behind nginx, Caddy or a load balancer that sets `X-Forwarded-For` and doesn't buffer the stream. One container works with the default in-memory limits; with several, use a shared store.
147
+
148
+ **OpenNext.** On AWS Lambda, the function must run on Node.js with response streaming on, and with a timeout longer than `turnTimeoutMs`, at every layer in front of it as well. Every concurrent Lambda instance has its own memory, so use a shared store. The Cloudflare adapter runs the app on Workers, which isn't Node.js: it isn't supported.
149
+
150
+ **Edge runtimes won't work.** askdare supports only the Node.js runtime. Don't set `export const runtime = 'edge'` on the chat route, and don't deploy it to a platform that runs only edge or worker functions.
151
+
152
+ ## Sources
153
+
154
+ - AI Act: [Regulation (EU) 2024/1689](https://eur-lex.europa.eu/eli/reg/2024/1689/oj/eng), Articles 3(3), 50, 111 and 113; [consolidated text of 27 July 2026](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:02024R1689-20260727).
155
+ - Digital Omnibus on AI: [Regulation (EU) 2026/1744](https://eur-lex.europa.eu/eli/reg/2026/1744/oj/eng), in force since 27 July 2026.
156
+ - GDPR: [Regulation (EU) 2016/679](https://eur-lex.europa.eu/eli/reg/2016/679/oj/eng), Articles 5, 13, 17, 28, 45 and 46.
157
+ - ePrivacy Directive: [Directive 2002/58/EC](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:02002L0058-20091219), Article 5(3), as amended by Directive 2009/136/EC.
158
+ - European Accessibility Act: [Directive (EU) 2019/882](https://eur-lex.europa.eu/eli/dir/2019/882/oj/eng), Articles 2, 4(5) and 31.
159
+ - [ETSI EN 301 549 V4.1.1 (2026-09)](https://www.etsi.org/deliver/etsi_en/301500_301599/301549/04.01.01_60/en_301549v040101p.pdf), Accessibility requirements for ICT products and services.
160
+ - OpenAI: [Data Processing Addendum](https://openai.com/policies/data-processing-addendum/), [Data controls](https://developers.openai.com/api/docs/guides/your-data), [Data residency](https://developers.openai.com/api/docs/guides/data-residency), [Safety best practices](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
@@ -85,7 +85,12 @@ export const { GET, POST, DELETE } = createChatHandler({
85
85
  | `knowledge` | `KnowledgeConfig` | off | Documents the model searches and cites. See [Knowledge](#knowledge). |
86
86
  | `attachments` | `AttachmentConfig` | off | Images and PDFs from visitors. See [Attachments](#attachments). |
87
87
  | `voice` | `VoiceConfig` | off | Dictation. See [Voice](#voice). |
88
+ | `moderation` | `ModerationConfig` | off | OpenAI moderation of messages, answers or both. See [Guardrails](guardrails.md#moderation). |
89
+ | `onInput` | `(text, context) => GuardVerdict \| undefined` | off | Your rule for each visitor message: allow, block or redact. See [Guardrails](guardrails.md#your-own-rules-oninput-and-onoutput). |
90
+ | `onOutput` | `(text, context) => GuardVerdict \| undefined` | off | Your rule for each finished answer. Answers are then held back until checked. See [Guardrails](guardrails.md#streaming-while-answers-are-checked). |
91
+ | `toolResults` | `'trusted' \| 'untrusted'` | `'trusted'` | `'untrusted'` marks tool results as third-party data for the model. See [Guardrails](guardrails.md#untrusted-tool-results). |
88
92
  | `security` | `BotSecurity` | own origin only | Sites that may embed the chat. See [Security](#security). |
93
+ | `embedPath` | `string` | off: askdare's own page | A page of this app to show in the widget's iframe instead of askdare's, such as `/askdare/support`. A path of the app, outside the chat route, without a query, a fragment or `.`/`..` segments. See [Your own page in the iframe](#your-own-page-in-the-iframe). |
89
94
  | `limits` | `BotLimits` | see [Limits](#limits) | Rates and budgets. |
90
95
  | `widget` | `WidgetConfig` | see [Widget](#widget) | Texts, language and look. |
91
96
 
@@ -150,6 +155,55 @@ The list holds at most 50 origins. Duplicates are dropped. A wrong entry fails w
150
155
 
151
156
  To check that a site may embed the chat, run `npx @boldare/askdare doctor --origin https://www.example.com`.
152
157
 
158
+ #### Human check
159
+
160
+ `security.humanVerifier` asks visitors to pass a human check before a new chat session starts ([ADR-0019](https://github.com/boldare/askdare/blob/main/docs/adr/0019-compliance-and-guardrails.md), [ADR-0023](https://github.com/boldare/askdare/blob/main/docs/adr/0023-human-check-and-react-budget.md)). It is off when absent, and a bot without it works as before. askdare ships one verifier, for [Cloudflare Turnstile](https://developers.cloudflare.com/turnstile/):
161
+
162
+ ```ts
163
+ import { defineBot, turnstile } from '@boldare/askdare';
164
+
165
+ defineBot({
166
+ // …
167
+ security: {
168
+ allowedOrigins,
169
+ // The site key is public; the secret key comes from TURNSTILE_SECRET_KEY.
170
+ humanVerifier: turnstile({ siteKey: '0x4AAAAAAA…' }),
171
+ },
172
+ });
173
+ ```
174
+
175
+ | `turnstile()` option | Type | Default | Notes |
176
+ | --- | --- | --- | --- |
177
+ | `siteKey` | `string` | required | The widget's site key from the Cloudflare dashboard. Browsers receive it. |
178
+ | `secretKey` | `string` | `process.env.TURNSTILE_SECRET_KEY` | The widget's secret key, read at the first check, so `next build` doesn't need it. Never commit it. |
179
+ | `hostnames` | `string[]` | not checked | Host names the challenge may have been solved on, compared with siteverify's `hostname`: your chat route's app, such as `['www.example.com']`. Off by default: the widget's hostname list in the Cloudflare dashboard already limits where it runs, and a proxy that serves the app under another name would be refused. |
180
+
181
+ How it works:
182
+
183
+ - When the chat needs a new session (the first message, a stored conversation to load, an upload), it shows the Turnstile widget in the chat (`HumanCheck`, part `human-check`) and waits for its token. In Turnstile's managed mode most visitors only see it for a moment. A page that calls `askdare('identify')` with a token (or `Root` with `identity`) opens the session at once, to find that user's conversation, so signed-in visitors see the check as the chat loads; anonymous visitors see it at their first action.
184
+ - Turnstile retries a failed challenge or a network error by itself, every 8 seconds; the chat gives up at the third error and shows `error.humanCheck`.
185
+ - `POST /session` sends the token to Cloudflare's siteverify endpoint, after the session rate limit. A token that fails, has expired or was already used answers `unauthorized`, with the text `error.humanCheck`; the next message shows a new challenge.
186
+ - The chat renders the widget with the bot's id as Turnstile's `action` (cut to 32 characters), and the server refuses a token whose `action` differs, such as one solved for another bot or another widget on the same site key. Cloudflare's test secret keys return no `action` and the hostname `example.com`, so with them neither the action nor `hostnames` is checked.
187
+ - Renewing a live session (an access token at most an hour past its expiry) needs no new check, for **24 hours** after the check was passed. Then, and for sessions that never passed one (such as sessions from before the bot turned the check on), the visitor passes it again and keeps their session. A visitor who comes back later with a stored conversation passes the check again.
188
+ - If Cloudflare can't be reached, or rejects the secret key, the session is refused (`upstream_error` or `bot_unavailable`) and `onError` receives it: the check fails closed.
189
+ - The iframe's Content Security Policy adds `https://challenges.cloudflare.com` to `script-src` and `frame-src`, for this bot only ([Embedding](embedding.md#what-your-app-sends-back)). The loader on the host page doesn't change.
190
+ - A chat inside your page (`Root`, `DefaultChat`) or your own page in the iframe (`embedPath`) runs under your page's policy: allow the same origin there. A headless chat must render `HumanCheck`, or it can't connect; the console says so.
191
+ - **Cloudflare's script runs with your app's access.** `api.js` is loaded from `challenges.cloudflare.com` into the chat's document: the iframe, on your app's origin, or your own page for a chat inside it. There it can do what your own scripts can, such as read the conversation on screen and the resume token in storage. Cloudflare changes the script without notice, so it can't carry Subresource Integrity, and askdare loads it without. Turning the check on means trusting Cloudflare with that.
192
+
193
+ Test it with Cloudflare's [test keys](https://developers.cloudflare.com/turnstile/troubleshooting/testing/), such as the site key `1x00000000000000000000AA` with the secret key `1x0000000000000000000000000000000AA`, which always pass.
194
+
195
+ To check tokens another way, pass your own object with the `HumanVerifier` type: `challenge` is what the chat renders (only `{ provider: 'turnstile', siteKey }` in 0.5), and `verify(token, { botId, signal })` resolves `true` for a person and `false` for a token that fails. Throw when the check can't run; the session is then refused.
196
+
197
+ ### Your own page in the iframe
198
+
199
+ By default the widget's iframe shows askdare's own page, which needs nothing from you. With `embedPath`, it shows a page of your app instead, so the widget on other sites can use your own components and [tool cards](react.md#tool-cards) ([ADR-0018](https://github.com/boldare/askdare/blob/main/docs/adr/0018-embed-path.md)). The chat route redirects the iframe to that path, with the visitor's language (`lang`, for a bot with `locale: 'auto'`) and the mode (`mode=inline`) in the query; the loader on the embedding site doesn't change. The redirect goes to `embedPath` exactly as you write it, so in an app with `basePath` in `next.config.ts` include that prefix (`/help/askdare/support`).
200
+
201
+ The page must send the headers askdare's own page sends. `@boldare/askdare/next` gives you both halves:
202
+ - `getEmbedConfig({ bots, bot, searchParams })` reads the language and the mode from the page's search parameters and returns the bot's public configuration, its allowed origins and the mode.
203
+ - `embedPageHeaders({ bots, bot })` returns the page's headers: `frame-ancestors` with the app and `security.allowedOrigins`, a `Permissions-Policy` that keeps the microphone off unless the bot has voice input, and `Referrer-Policy: strict-origin`. Send them from `proxy.ts`.
204
+
205
+ The page renders `EmbedRoot` from `@boldare/askdare/embed`. [Embedding: your own page in the iframe](embedding.md#your-own-page-in-the-iframe) walks through it. `npx @boldare/askdare doctor` follows the redirect and checks the page: no login or redirect in front of it, `EmbedRoot` on it, who may frame it and the microphone rule.
206
+
153
207
  ### Limits
154
208
 
155
209
  Limits bound what visitors can cost ([ADR-0004](https://github.com/boldare/askdare/blob/main/docs/adr/0004-threat-model.md)). Every limit applies per bot, and every value is a whole number.
@@ -214,7 +268,7 @@ Everything in `widget` is sent to browsers. Never put secrets in it. [Styling](s
214
268
  | `colorScheme` | `'auto' \| 'light' \| 'dark'` | `'auto'` | `'auto'` follows the visitor's system setting. |
215
269
  | `css` | `string` | none | Your own CSS, up to 50,000 characters. It loads after the theme. |
216
270
 
217
- The text defaults come from the built-in dictionary of the configured language. The table shows the English ones, which `'auto'` also uses. Texts ship in English and Polish.
271
+ The text defaults come from the built-in dictionary of the configured language. The table shows the English ones, which `'auto'` also uses. Texts ship in English, Czech, German, Spanish, French, Italian and Polish.
218
272
 
219
273
  ## `createChatHandler`
220
274
 
@@ -222,7 +276,7 @@ The text defaults come from the built-in dictionary of the configured language.
222
276
 
223
277
  | Option | Type | Default | Notes |
224
278
  | --- | --- | --- | --- |
225
- | `bots` | `readonly Bot[]` | required | At least one bot. IDs must be unique. |
279
+ | `bots` | `readonly BotHandle[]` | required | At least one bot from `defineBot`. IDs must be unique. |
226
280
  | `basePath` | `string` | `'/api/chat'` | Path of the catch-all route. One or more segments of letters, digits, `.`, `_`, `~` or `-`, each after a `/`. No trailing slash. |
227
281
  | `openaiApiKey` | `string` | `process.env.OPENAI_API_KEY` | The OpenAI API key. |
228
282
  | `secret` | `string` | `process.env.CHAT_SECRET` | Encrypts session tokens and attachment handles. At least 32 characters, with at least 12 different ones. Use `openssl rand -base64 32`. |
@@ -245,6 +299,7 @@ A wrong `basePath`, a duplicate bot ID or an empty `bots` list throws a `TypeErr
245
299
  | `store` | `RateLimitStore` | in memory, per process | Counter storage for rate limits and budgets. With more than one instance, use a shared store such as `@boldare/askdare-upstash`. See [Custom rate-limit store](custom-store.md). |
246
300
  | `trustProxy` | `'auto' \| 'vercel' \| 'heroku' \| number` | `'auto'` | How to read the client IP behind your proxy. |
247
301
  | `globalDailyTokens` | `number` | unlimited | Input plus output tokens per UTC day, across all bots of this handler. Reaching it answers `budget_exceeded`. |
302
+ | `requireSharedStore` | `boolean` | `false` | `true` makes `createChatHandler` throw as the route loads unless `store` is shared (`shared: true`), instead of only warning in production. For example `process.env.NODE_ENV === 'production'`, so development keeps the in-memory store. Note that `next build` loads the route with `NODE_ENV=production`. |
248
303
 
249
304
  ### `trustProxy`
250
305
 
@@ -383,6 +438,7 @@ It must be a literal in the route file. It is the longest a streamed answer may
383
438
  | `CHAT_SECRET` | `createChatHandler`, `npx @boldare/askdare doctor` | Default for `secret`. Required. `doctor` signs its request to your app with it. |
384
439
  | `CHAT_SECRET_PREVIOUS` | `createChatHandler`, `npx @boldare/askdare doctor` | Former secrets, comma-separated. Default for `previousSecrets`. |
385
440
  | `IDENTITY_SECRET` | `createChatHandler`, `npx @boldare/askdare doctor` | Default for `identitySecret`. Optional: without it, identity is off. |
441
+ | `TURNSTILE_SECRET_KEY` | `turnstile()` | Default for `secretKey`, read at the first human check. Needed only for a bot with `security.humanVerifier: turnstile(…)`. |
386
442
  | `ASKDARE_DISABLED` | `createChatHandler` | The kill switch. When it is exactly `true`, every bot answers `bot_unavailable`. askdare reads it on every request. |
387
443
  | `KB_VECTOR_STORE_ID` | `npx @boldare/askdare kb sync` | The vector store to sync, unless you pass `--store`. |
388
444
  | `ASKDARE_MODEL` | `npx @boldare/askdare doctor` | `doctor` reports it when it is missing or empty and your `askdare.config` uses it. The server doesn't read it; your config does. |
package/docs/costs.md CHANGED
@@ -12,6 +12,7 @@ Prices change often, so this page counts tokens, seconds and files. To turn them
12
12
  | Knowledge base | Retrieved chunks as input tokens, a fee per file search call, and vector store storage per GB per day above a free allowance | Only the tokens are in the budgets |
13
13
  | Attachments | Images and PDF pages as input tokens, when they are sent | The token budgets, plus upload limits |
14
14
  | Voice input | Transcription, per minute of audio (some models bill by tokens instead) | Daily speech budgets in seconds |
15
+ | Moderation | Nothing extra today: OpenAI's moderation endpoint is free. Each checked message adds one call and its latency | Only bots with `moderation` make the call |
15
16
  | `askdare doctor` | A 16-token response, plus one second of transcription for bots with voice, per bot and run | 3 runs a minute for the whole app |
16
17
 
17
18
  ## The worst case under the default limits
@@ -154,7 +155,7 @@ The model decides most of the bill, which is why askdare never picks one for you
154
155
  A conversation is stored by OpenAI, and every message sends the whole conversation to the model as input. Each message therefore costs more than the one before.
155
156
 
156
157
  - `maxTurns` (default 50) ends a conversation: the visitor is asked to start a new one.
157
- - askdare sends `truncation: 'auto'`. When a conversation outgrows the model's context window, OpenAI drops the oldest items instead of failing.
158
+ - askdare sends `truncation: 'auto'`. When a conversation outgrows the model's context window, OpenAI drops the oldest items instead of failing. OpenAI has deprecated the parameter but announced no shutdown date; askdare keeps sending it until then. If OpenAI ever refuses an overflowing conversation, the visitor sees "This conversation is too long. Please start a new one."
158
159
  - askdare doesn't compact or summarize conversations. OpenAI's server-side compaction isn't planned for a release yet: in spikes [S5](https://github.com/boldare/askdare/blob/main/spikes/s5-compaction/README.md) and S5b it cut answers off, ran on every turn and lost prompt caching ([ADR-0003](https://github.com/boldare/askdare/blob/main/docs/adr/0003-conversation-state.md)).
159
160
  - Attached files and your tools' results stay in the conversation, so every later message reads them again. Keep tool results small ([Tools](tools.md)).
160
161
 
@@ -189,6 +190,12 @@ The extra call counts against `maxSteps` and the budgets like a tool round: askd
189
190
  - Every model call reads the files again. A bot with tools reserves the files once per call it actually makes, so a large PDF can mean the model answers without calling tools when the visitor's budget can't hold another call.
190
191
  - Keep attachments off for bots that don't need them, and lower `maxPdfPages` if long PDFs aren't expected. See [Attachments](attachments.md).
191
192
 
193
+ ## Moderation
194
+
195
+ - A bot with `moderation` makes one call to OpenAI's moderation endpoint per checked message: one before the turn for `check: 'input'`, one after the answer for `'output'`, two for `'both'`. Bots without it make none.
196
+ - The endpoint is free to use at the time of writing ([OpenAI's moderation guide](https://developers.openai.com/api/docs/guides/moderation)), so it adds latency, not tokens, and isn't in askdare's budgets. Check the pricing page again if that changes.
197
+ - Checking output holds each answer back until it is complete, so visitors wait longer before they see anything. A blocked answer has still spent its tokens, and they count against the budgets. See [Guardrails](guardrails.md).
198
+
192
199
  ## Voice input
193
200
 
194
201
  - Transcription is billed per minute of audio for models that report a duration. askdare reserves `voice.maxSeconds` (default 60) per dictation and then charges the duration OpenAI reports.
@@ -59,6 +59,8 @@ askdare uses refunds to give back a reservation. A turn reserves an estimate aga
59
59
  - When `shared` is `false` and `NODE_ENV` is `production`, `createChatHandler` logs a warning as the route loads: `[askdare] Rate limits are kept in memory, per instance. With more than one instance, use a shared store such as @boldare/askdare-upstash.`
60
60
  - `npx @boldare/askdare doctor` warns that rate limits and budgets are kept per instance, unless the app runs in development.
61
61
 
62
+ With `limits: { requireSharedStore: true }`, `createChatHandler` throws instead, as the route loads, when the store's `shared` is `false` ([Handler limits](configuration.md#handler-limits)). Turn it on in production when per-instance limits would be a bug, not a trade-off.
63
+
62
64
  Set `shared: true` only when every instance reaches the same counters, such as a database they all connect to. A store that keeps counters inside the process is `shared: false`, even if you wrote it.
63
65
 
64
66
  ## Example: PostgreSQL
package/docs/embedding.md CHANGED
@@ -117,6 +117,8 @@ The chat page, `/api/chat/embed/<bot>`, answers with these headers:
117
117
  | `X-Content-Type-Options` | `nosniff` |
118
118
  | `Cache-Control` | `no-store` |
119
119
 
120
+ A bot with a human check (`security.humanVerifier`) also allows Cloudflare Turnstile in its own policy, and nothing else: `script-src 'self' https://challenges.cloudflare.com` and `frame-src https://challenges.cloudflare.com` ([Configuration](configuration.md#human-check)).
121
+
120
122
  `frame-ancestors` decides who may embed the chat: `'self'`, which is your app, plus the bot's `security.allowedOrigins`. With `allowedOrigins: ['https://www.example.com']`, the header ends in `frame-ancestors 'self' https://www.example.com`. Browsers enforce it, so the list holds even if someone copies the snippet.
121
123
 
122
124
  `widget.js` is served with `Cache-Control: public, max-age=300, stale-while-revalidate=86400`, or `no-cache` under `next dev`. A new button look can take a few minutes to show on other sites.
@@ -216,6 +218,108 @@ An inline chat inside a React app has a hydration caveat. [Styling](styling.md#3
216
218
 
217
219
  In the Next.js app that serves the chat, you can also render it without an iframe, as React components in your own pages: see [The chat inside your page](react.md).
218
220
 
221
+ ## Your own page in the iframe
222
+
223
+ By default the widget's iframe shows askdare's own page, built with the default look: it needs nothing from you and nothing on your side can break it. A bot can show a page of your app there instead, so the widget on every site that embeds it uses your own components and draws your [tool cards](react.md#tool-cards) ([ADR-0018](https://github.com/boldare/askdare/blob/main/docs/adr/0018-embed-path.md)). The snippet on those sites stays the same.
224
+
225
+ **1. Point the bot at a page.** A path of your app, outside the chat route:
226
+
227
+ ```ts
228
+ // askdare.config.ts
229
+ defineBot({ id: 'support', /* … */ embedPath: '/askdare/support' });
230
+ ```
231
+
232
+ The chat route now redirects the iframe there, with `lang` (for a bot with `locale: 'auto'`) and `mode=inline` (for an inline chat) in the query.
233
+
234
+ **2. Give the page its own root layout.** Put it in a route group with its own `<html>` and `<body>`, so nothing of your site (its header, navigation, fonts, analytics or chat widget) renders or runs inside the widget on other sites. With a group of its own, your other pages move into a group too, such as `app/(site)/`:
235
+
236
+ ```tsx
237
+ // app/(askdare)/layout.tsx
238
+ import './frame.css'; // html, body { height: 100%; margin: 0 }
239
+
240
+ export default function FrameLayout({ children }: { readonly children: React.ReactNode }) {
241
+ return (
242
+ <html lang="en">
243
+ <body>{children}</body>
244
+ </html>
245
+ );
246
+ }
247
+ ```
248
+
249
+ **3. Render the chat with `EmbedRoot`.** The page reads its configuration in a Server Component; a client component renders it:
250
+
251
+ ```tsx
252
+ // app/(askdare)/askdare/support/page.tsx
253
+ import { getEmbedConfig } from '@boldare/askdare/next';
254
+ import { Suspense } from 'react';
255
+ import { bots } from '@/askdare.config';
256
+ import { FramedChat } from './framed-chat';
257
+
258
+ type Search = Promise<Record<string, string | string[] | undefined>>;
259
+
260
+ export default function Page({ searchParams }: { searchParams: Search }) {
261
+ // With Cache Components (as in the starter), the request's data is read inside Suspense.
262
+ return (
263
+ <Suspense>
264
+ <Chat searchParams={searchParams} />
265
+ </Suspense>
266
+ );
267
+ }
268
+
269
+ async function Chat({ searchParams }: { searchParams: Search }) {
270
+ const config = getEmbedConfig({ bots, bot: 'support', searchParams: await searchParams });
271
+ return <FramedChat config={config} />;
272
+ }
273
+ ```
274
+
275
+ ```tsx
276
+ // app/(askdare)/askdare/support/framed-chat.tsx
277
+ 'use client';
278
+ import { type EmbedChatConfig, EmbedRoot } from '@boldare/askdare/embed';
279
+ import * as Chat from '@boldare/askdare/react';
280
+ import { toolRenderers } from '@/components/tool-cards';
281
+
282
+ export function FramedChat({ config }: { config: EmbedChatConfig }) {
283
+ return (
284
+ <EmbedRoot config={config} toolRenderers={toolRenderers}>
285
+ <Chat.DefaultChat className="framed-chat" />
286
+ </EmbedRoot>
287
+ );
288
+ }
289
+ ```
290
+
291
+ `EmbedRoot` connects to the loader on the embedding site exactly as askdare's own page does: `askdare('identify')`, `configure`, `on`, opening, closing and language switches all work. Inside it, `DefaultChat` is the page's main landmark with an `h1`, and shows a close button. Instead of `DefaultChat`, you can use an [ejected copy](react.md#eject-the-default-look), which behaves the same, or [your own markup](react.md#your-own-markup), where `useFrame()` gives you the close action for your own button.
292
+
293
+ **4. Send the iframe page's headers.** Without them, any site could frame the page, and the microphone would follow your app's policy. Set them in `proxy.ts`, per request:
294
+
295
+ ```ts
296
+ // proxy.ts
297
+ import { embedPageHeaders } from '@boldare/askdare/next';
298
+ import { type NextRequest, NextResponse } from 'next/server';
299
+ import { bots } from './askdare.config';
300
+
301
+ export function proxy(request: NextRequest) {
302
+ const response = NextResponse.next();
303
+ const bot = bots.find((item) => item.embedPath === request.nextUrl.pathname);
304
+ for (const { key, value } of bot ? embedPageHeaders({ bots, bot: bot.id }) : []) {
305
+ response.headers.set(key, value);
306
+ }
307
+ return response;
308
+ }
309
+
310
+ export const config = { matcher: '/askdare/:bot' };
311
+ ```
312
+
313
+ Not `headers()` in `next.config.ts`, unless the allowed origins are written in your code: Next.js evaluates it when the app is built, so origins from the environment where it runs would be missing, and the widget wouldn't open on those sites. If you already have a `proxy.ts` that signs visitors in or rewrites paths (i18n), leave the page's path out of what it does: the page must answer without a redirect.
314
+
315
+ **5. Check it.** Run `npx @boldare/askdare doctor --origin https://www.example.com`. It follows the redirect and checks the page: it answers without a redirect, renders `EmbedRoot`, may be framed by the app and every allowed origin and by nothing else, and keeps the microphone off unless the bot has voice input.
316
+
317
+ Things to know:
318
+ - **The page runs your scripts with the chat's origin,** as [the chat inside your page](react.md) does: they could read the visitor's session. Load no third-party scripts on it; the root layout of its own keeps your site's out.
319
+ - **The page is rendered per request** (it reads its search parameters). Don't cache it.
320
+ - **It opens a moment later** than askdare's own page: one redirect, and your page hydrates before the chat connects. Until then, the Send button stays off.
321
+ - **In an app with `basePath`** in `next.config.ts`, include that prefix in `embedPath`.
322
+
219
323
  ## Staging and production
220
324
 
221
325
  Each environment usually embeds the chat on different sites. Read the list from an environment variable, for example `ASKDARE_ALLOWED_ORIGINS`, split on commas:
package/docs/events.md CHANGED
@@ -73,7 +73,7 @@ Every event has `type` and `bot`, the bot's ID. The other fields depend on the t
73
73
  | `length` | number | The message's length in characters. |
74
74
  | `attachments` | number | How many images and PDFs it carried. |
75
75
  | `source` | `'typed'`, `'starter'` or `'reply'` | Typed or dictated into the field, picked from the suggested questions before the conversation, or picked from the [options](reply-options.md) under the latest answer. |
76
- | `outcome` | `'completed'`, `'failed'` or `'stopped'` | `stopped` when the chat was taken down mid-answer, as when a React `Root` unmounts or the chat reloads in another language. |
76
+ | `outcome` | `'completed'`, `'failed'` or `'stopped'` | `stopped` when the chat was taken down mid-answer, as when a React `Root` unmounts or the chat has to reload in another language. |
77
77
  | `durationMs` | number | From sending the message to the end of the answer. |
78
78
  | `citations` | number | How many sources the answer cites. |
79
79
  | `rating` | `'up'`, `'down'` or `null` | `null` when the visitor took their rating back. |
package/docs/feedback.md CHANGED
@@ -165,6 +165,6 @@ To do several of these, call them one after another in a single `onFeedback`.
165
165
 
166
166
  ## Texts and styling
167
167
 
168
- - **Texts:** `feedback.label`, `feedback.up`, `feedback.down`, `feedback.comment`, `feedback.send` and `feedback.skip`, in English and Polish. Override them with `widget.texts` like any other ([Texts](texts.md)).
168
+ - **Texts:** `feedback.label`, `feedback.up`, `feedback.down`, `feedback.comment`, `feedback.send` and `feedback.skip`, in every built-in language. Override them with `widget.texts` like any other ([Texts](texts.md)).
169
169
  - **Parts:** `feedback` (the two buttons), `feedback-button` (with `data-rating="up"` or `"down"`, and `aria-pressed`), `feedback-comment`, `feedback-comment-input`, `feedback-comment-actions`, `feedback-skip` and `feedback-send` ([Styling](styling.md)).
170
170
  - **In your own markup:** `FeedbackButton` from `@boldare/askdare/react`, and `actions.rate(messageId, rating, comment?)` with `state.commenting` for the question after a 👎.
@@ -21,6 +21,7 @@ openssl rand -base64 32 # use the output as CHAT_SECRET
21
21
  | `CHAT_SECRET` | yes | At least 32 random characters. Never commit it. |
22
22
  | `CHAT_SECRET_PREVIOUS` | during rotation | Comma-separated former secrets |
23
23
  | `IDENTITY_SECRET` | for signed-in visitors | Shared with your site's backend only; never in a page or in git |
24
+ | `TURNSTILE_SECRET_KEY` | for a human check | The Turnstile widget's secret key; see step 3 |
24
25
  | `ASKDARE_DISABLED` | no | Set `true` to switch every bot off. It takes effect when the app restarts with the new value: on Vercel, redeploy; on Heroku, changing a config var restarts the dynos. |
25
26
 
26
27
  **To rotate the secret:**
@@ -32,6 +33,8 @@ openssl rand -base64 32 # use the output as CHAT_SECRET
32
33
  - **`security.allowedOrigins`:** the exact sites allowed to embed the widget, such as `https://www.example.com`. No paths and no wildcards. The app's own origin is always allowed.
33
34
  - **`limits`:** start with the defaults and tune `dailyTokens` (per bot) and `dailyTokensPerIp` to your budget. Add `limits: { globalDailyTokens }` to `createChatHandler` to cap all bots together. These budgets are the main cost control; the OpenAI hard limit is the backstop.
34
35
  - **Instructions:** they must contain **no secrets**. Assume visitors can make the model reveal them.
36
+ - **Guardrails:** decide whether the bot needs OpenAI moderation (`moderation`), your own rules for messages and answers (`onInput`, `onOutput`), or untrusted tool results (`toolResults: 'untrusted'`) for tools that return third-party text. All are off by default. See [Guardrails](guardrails.md).
37
+ - **Human check (optional):** limits bound what one address can spend, not what many addresses can. For a public chat that attracts scripted abuse, add `security.humanVerifier: turnstile({ siteKey })` and set `TURNSTILE_SECRET_KEY`. Visitors then pass Cloudflare Turnstile when a session starts ([Configuration](configuration.md#human-check)). Create the widget in the Cloudflare dashboard with your app's host name, not the sites that embed the chat: the challenge runs in the chat's iframe, on your app's origin. Name Cloudflare in your privacy notice.
35
38
 
36
39
  ## 4. Rate limits across instances
37
40
 
@@ -46,6 +49,12 @@ export const { GET, POST, DELETE } = createChatHandler({
46
49
  });
47
50
  ```
48
51
 
52
+ To make sure a production deployment never runs with per-instance counters, add `requireSharedStore`. The route then refuses to load without a shared store, instead of logging a warning:
53
+
54
+ ```ts
55
+ limits: { store: upstashStore(), requireSharedStore: process.env.NODE_ENV === 'production' },
56
+ ```
57
+
49
58
  **Client IP:**
50
59
  - The client IP comes from proxy headers. The default `trustProxy: 'auto'` detects Vercel and assumes one proxy otherwise, which matches Heroku.
51
60
  - Behind additional proxies (a CDN in front of Heroku, for example), set `trustProxy` to the number of proxies.
@@ -67,16 +76,19 @@ export const { GET, POST, DELETE } = createChatHandler({
67
76
  - Clients with data-residency or zero-retention requirements need the planned own-storage add-on.
68
77
  - **Disclosures:**
69
78
  - Publish a privacy notice that names OpenAI (and Upstash, if used) as processors.
70
- - Tell visitors they are talking to an AI. The chat says so under the message field by default; add `widget.disclosure.privacyUrl` to link your privacy notice ([Styling](styling.md#1-configuration)).
79
+ - Tell visitors they are talking to an AI (EU AI Act, art. 50). The chat says so under the message field by default; add `widget.disclosure.privacyUrl` to link your privacy notice ([Styling](styling.md#1-configuration)). In your own markup, or your own page in the widget's iframe, place the `Disclosure` primitive ([React](react.md#your-own-markup)). `askdare doctor` lists bots with `disclosure: false`, so you can confirm each one is deliberate.
80
+ - **Compliance:** [Compliance](compliance.md) goes through the AI Act's disclosure duty, the GDPR (the DPA with OpenAI, retention and deletion), data residency, the resume token in a chat inside your page, accessibility and hosts other than Vercel and Heroku.
71
81
 
72
82
  ## 7. Final check
73
83
 
74
84
  - [ ] Restricted key, model allowlist and a hard spend limit, with a tested alert.
75
85
  - [ ] `CHAT_SECRET` is random, at least 32 characters, and not in git.
76
86
  - [ ] `allowedOrigins` lists only your sites.
77
- - [ ] Shared store configured if you run more than one instance.
87
+ - [ ] Shared store configured if you run more than one instance, and `requireSharedStore` on if that must never be forgotten.
88
+ - [ ] If the chat is public and anonymous, you decided whether it needs a human check, and tested it with Cloudflare's test keys.
78
89
  - [ ] Instructions contain no secrets.
79
- - [ ] Privacy notice, retention decision and AI disclosure are in place.
90
+ - [ ] Guardrails decided: moderation, `onInput`/`onOutput` and `toolResults` ([Guardrails](guardrails.md)).
91
+ - [ ] Privacy notice, retention decision and AI disclosure are in place, checked against [Compliance](compliance.md).
80
92
  - [ ] If visitors rate answers, your notice covers their comments, and `onFeedback` keeps them no longer than you need.
81
93
  - [ ] You know how to flip `ASKDARE_DISABLED=true` and redeploy or restart, and how long that takes on your host.
82
94
  - [ ] `npx @boldare/askdare doctor --url <your app> --env-file <production env>` reports no problems ([Deployment](deployment.md)).