@boldare/askdare 0.1.0-rc.4 → 0.2.0-rc.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.
- package/CHANGELOG.md +56 -0
- package/README.md +12 -4
- package/dist/cli.js +286 -176
- package/dist/index.js +2 -0
- package/dist/next.d.ts +169 -4
- package/dist/next.js +395 -87
- package/dist/react-marked.js +1797 -0
- package/dist/react.d.ts +470 -0
- package/dist/react.js +2691 -0
- package/dist/store.d.ts +13 -0
- package/dist/ui/askdare.css +1720 -0
- package/dist/ui/avatar.tsx +27 -0
- package/dist/ui/chat.tsx +26 -0
- package/dist/ui/confirm.tsx +71 -0
- package/dist/ui/context.ts +31 -0
- package/dist/ui/feedback.tsx +78 -0
- package/dist/ui/footer.tsx +60 -0
- package/dist/ui/header.tsx +51 -0
- package/dist/ui/icons.tsx +89 -0
- package/dist/ui/index.ts +8 -0
- package/dist/ui/message.tsx +21 -0
- package/dist/ui/panel.tsx +121 -0
- package/dist/ui/welcome.tsx +88 -0
- package/dist/version.js +12 -0
- package/docs/cli.md +30 -0
- package/docs/configuration.md +74 -4
- package/docs/costs.md +7 -1
- package/docs/embedding.md +2 -0
- package/docs/feedback.md +54 -0
- package/docs/getting-started.md +3 -0
- package/docs/going-public.md +1 -0
- package/docs/observability.md +76 -0
- package/docs/privacy.md +27 -7
- package/docs/protocol.md +13 -3
- package/docs/react.md +283 -0
- package/docs/styling.md +14 -2
- package/docs/support.md +4 -2
- package/docs/texts.md +6 -0
- package/docs/troubleshooting.md +12 -0
- package/llms.txt +5 -2
- package/package.json +19 -7
- package/skills/askdare/SKILL.md +6 -2
package/docs/react.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# The chat inside your page (React)
|
|
2
|
+
|
|
3
|
+
`@boldare/askdare/react` renders the chat in a page of your own Next.js app, as React components instead of an iframe. You get the widget's look ready to place, or hooks and primitives to write your own markup ([ADR-0011](https://github.com/boldare/askdare/blob/main/docs/adr/0011-react-api-and-inline-chat.md)). Streaming, limits and security stay in the library either way.
|
|
4
|
+
|
|
5
|
+
| You want | Use |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| A chat button on any site, also sites that aren't yours | The script-tag widget ([Embedding](embedding.md)) |
|
|
8
|
+
| The chat as part of a page of your Next.js app | `DefaultChat`, below |
|
|
9
|
+
| Your own markup and CSS | [The primitives](#your-own-markup) |
|
|
10
|
+
| To change the default components themselves | [`add ui`](#eject-the-default-look) |
|
|
11
|
+
|
|
12
|
+
**Before you start:**
|
|
13
|
+
|
|
14
|
+
- It needs React 19 and the same app that serves the chat route. The chat talks only to its own origin: it can't be used from another site. For that, use the widget.
|
|
15
|
+
- **A chat inside a page is as safe as the page.** Scripts on the page can read the conversation and the visitor's session, which the widget's iframe keeps from them. On pages that run scripts you don't trust (ads, tag managers with third-party tags), keep the widget.
|
|
16
|
+
|
|
17
|
+
## Set up
|
|
18
|
+
|
|
19
|
+
You need the chat route from [Getting started](getting-started.md). Then:
|
|
20
|
+
|
|
21
|
+
**1. Read the bot's public configuration in a Server Component** and render the chat with it:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
// app/help/page.tsx
|
|
25
|
+
import { getChatConfig } from '@boldare/askdare/next';
|
|
26
|
+
import { DefaultChat, Root } from '@boldare/askdare/react';
|
|
27
|
+
import { bots } from '@/askdare.config';
|
|
28
|
+
|
|
29
|
+
export default function HelpPage() {
|
|
30
|
+
const config = getChatConfig({ bots, bot: 'support' });
|
|
31
|
+
return (
|
|
32
|
+
<Root config={config}>
|
|
33
|
+
<DefaultChat className="help-chat" />
|
|
34
|
+
</Root>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**2. Give the chat a height.** It fills the element it is in:
|
|
40
|
+
|
|
41
|
+
```css
|
|
42
|
+
.help-chat { height: 640px; }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
That is all: the components are client components already, and the chat loads its stylesheets from the chat route, so there is no CSS to import and nothing to configure in your bundler.
|
|
46
|
+
|
|
47
|
+
`getChatConfig(options)` returns only what browsers may see: texts, the theme's name and the URLs of the stylesheets. Never the model, instructions, tools or keys.
|
|
48
|
+
|
|
49
|
+
| Option | Default | Meaning |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| `bots` | required | The same bots as in `createChatHandler`. |
|
|
52
|
+
| `bot` | required | The ID of the bot to show. |
|
|
53
|
+
| `basePath` | `/api/chat` | The path of the chat route, if you changed it in `createChatHandler`. |
|
|
54
|
+
| `locale` | `en` | The page's language, for a bot with `locale: 'auto'`. A bot with a fixed locale keeps it. |
|
|
55
|
+
|
|
56
|
+
## `Root`
|
|
57
|
+
|
|
58
|
+
`Root` runs one bot's chat for the components inside it. It renders no element of its own.
|
|
59
|
+
|
|
60
|
+
| Prop | Meaning |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `config` | From `getChatConfig`. A different bot, route or language starts another chat. |
|
|
63
|
+
| `identity` | The signed-in visitor: a token from your backend, as for `askdare('identify')`. See [below](#signed-in-visitors). |
|
|
64
|
+
| `greeting`, `starters` | This page's greeting and up to 4 suggested questions, instead of the bot's. |
|
|
65
|
+
| `context` | A short description of the page for the assistant, up to 1,000 characters. Only for a bot with `pageContext: true`. |
|
|
66
|
+
|
|
67
|
+
`greeting`, `starters` and `context` are the same as in `askdare('configure')` and are checked the same way ([Styling](styling.md#3-page-javascript)).
|
|
68
|
+
|
|
69
|
+
### Signed-in visitors
|
|
70
|
+
|
|
71
|
+
Pass the identity token your backend signs ([Signed-in visitors](identity.md)):
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
<Root config={config} identity={token}>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- **To sign a visitor out, pass `identity={null}`.** Leaving the prop out, or passing `undefined`, keeps whoever is signed in. In a single-page app, a `Root` that stays mounted across a sign-out must get `null`.
|
|
78
|
+
- **A page that renders a token must not be cached.** The token is in the page's HTML, so render the page per request (for example by reading `cookies()`), and never serve it from a shared cache.
|
|
79
|
+
|
|
80
|
+
## `DefaultChat`
|
|
81
|
+
|
|
82
|
+
The widget's look: header, conversation, message field, attachments, dictation and ratings, as the bot is configured.
|
|
83
|
+
|
|
84
|
+
| Prop | Default | Meaning |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| `className` | | On the element that holds the chat. Give it a height. |
|
|
87
|
+
| `headingLevel` | `2` | The level of the chat's title; the welcome heading is one below. Pick what fits your page's outline. |
|
|
88
|
+
| `colorScheme` | the bot's | `'light'`, `'dark'` or `'auto'`, for example to follow your site's dark mode switch. |
|
|
89
|
+
| `onClose` | | Shows a close button. Escape, pressed in the chat, calls it too. |
|
|
90
|
+
| `components` | | Replaces `Header`, `Welcome`, `Message` or `Footer`. |
|
|
91
|
+
|
|
92
|
+
A replacement takes no props. It reads what it needs with the hooks:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
'use client';
|
|
96
|
+
import { DefaultChat, useChat } from '@boldare/askdare/react';
|
|
97
|
+
|
|
98
|
+
function Header() {
|
|
99
|
+
const { bot, state, actions } = useChat();
|
|
100
|
+
return (
|
|
101
|
+
<header>
|
|
102
|
+
<h2>{bot.title}</h2>
|
|
103
|
+
{state.messages.length > 0 && (
|
|
104
|
+
<button type="button" onClick={() => void actions.newConversation()}>Start over</button>
|
|
105
|
+
)}
|
|
106
|
+
</header>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function HelpChat() {
|
|
111
|
+
return <DefaultChat className="help-chat" components={{ Header }} />;
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The chat doesn't take focus or scroll to itself when the page loads. When an answer or a transcript arrives, it returns focus to the message field only if focus was in the chat or nowhere, never from your page's own fields, and without scrolling. `actions.focus()` always moves it. Escape pressed outside the chat is left to your page.
|
|
116
|
+
|
|
117
|
+
## Your own markup
|
|
118
|
+
|
|
119
|
+
Every primitive renders one element with its usual `data-ask-part` name ([Styling](styling.md)), and passes `className`, `ref` and other native props through. Write `import * as Chat` to keep them together:
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
'use client';
|
|
123
|
+
import * as Chat from '@boldare/askdare/react';
|
|
124
|
+
|
|
125
|
+
function Bubble() {
|
|
126
|
+
const message = Chat.useMessage();
|
|
127
|
+
return (
|
|
128
|
+
<Chat.Message className={message.role === 'user' ? 'mine' : 'theirs'}>
|
|
129
|
+
<Chat.MessageText />
|
|
130
|
+
<Chat.MessageFiles />
|
|
131
|
+
<Chat.Citations />
|
|
132
|
+
<Chat.FeedbackButton rating="up">👍</Chat.FeedbackButton>
|
|
133
|
+
<Chat.FeedbackButton rating="down">👎</Chat.FeedbackButton>
|
|
134
|
+
</Chat.Message>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function PlainChat({ config }: { config: Chat.ChatConfig }) {
|
|
139
|
+
return (
|
|
140
|
+
<Chat.Root config={config}>
|
|
141
|
+
<Chat.Panel className="plain-chat">
|
|
142
|
+
<Chat.Messages>
|
|
143
|
+
<Chat.MessageList>
|
|
144
|
+
<Bubble />
|
|
145
|
+
</Chat.MessageList>
|
|
146
|
+
<Chat.Status />
|
|
147
|
+
</Chat.Messages>
|
|
148
|
+
<Chat.ErrorMessage />
|
|
149
|
+
<Chat.Composer>
|
|
150
|
+
<Chat.Files />
|
|
151
|
+
<Chat.AttachButton>Attach</Chat.AttachButton>
|
|
152
|
+
<Chat.Input />
|
|
153
|
+
<Chat.DictateButton>Dictate</Chat.DictateButton>
|
|
154
|
+
<Chat.Recorder />
|
|
155
|
+
<Chat.Send>Send</Chat.Send>
|
|
156
|
+
</Chat.Composer>
|
|
157
|
+
</Chat.Panel>
|
|
158
|
+
</Chat.Root>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Without `Theme` and `DefaultChat`, no stylesheet of the chat loads: the look is all yours.
|
|
164
|
+
|
|
165
|
+
| Primitive | Element | What it does |
|
|
166
|
+
| --- | --- | --- |
|
|
167
|
+
| `Theme` | `div` | Sets the bot's tokens (`--ask-*`) and theme variants for everything inside, and loads the theme and its fonts. Takes `colorScheme`. |
|
|
168
|
+
| `Panel` | `section` | The chat's frame, a region named after the bot. Files dropped on it are attached. |
|
|
169
|
+
| `Messages` | `div` | The conversation, as a live region that follows the latest message. |
|
|
170
|
+
| `MessageList` | none | Renders its children once per message. |
|
|
171
|
+
| `Message` | `div` | One message, with `data-role` and `data-status`. |
|
|
172
|
+
| `MessageText` | `div` | The text: the visitor's as typed, an answer as Markdown, typing dots before the first word. |
|
|
173
|
+
| `Markdown` | none | Renders a `text` as the chat renders answers. |
|
|
174
|
+
| `Citations` | `ol` | The answer's sources. |
|
|
175
|
+
| `MessageFiles` | `ul` or `p` | The files sent with a message. |
|
|
176
|
+
| `FeedbackButton` | `button` | Rates the answer; takes `rating="up"` or `"down"`. See [Answer ratings](feedback.md). |
|
|
177
|
+
| `Composer` | `form` | Submitting it sends the draft, Enter in the `Input` included. An `onSubmit` of yours that calls `event.preventDefault()` takes the message over. |
|
|
178
|
+
| `Input` | `textarea` | The message field: Enter sends, Shift+Enter starts a new line, pasted files are attached. Your `onKeyDown` or `onPaste` can prevent either. |
|
|
179
|
+
| `Send` | `button` | Sends; disabled until there is something to send. |
|
|
180
|
+
| `AttachButton` | `button` | Opens the file picker. Renders nothing when the bot takes no attachments. |
|
|
181
|
+
| `Files` | `ul` | The files picked for the next message. |
|
|
182
|
+
| `DictateButton` | `button` | Starts a dictation. Renders nothing without voice input. |
|
|
183
|
+
| `Recorder` | `div` | The running dictation, with cancel and done. Renders nothing otherwise. |
|
|
184
|
+
| `Status` | `p` | What the assistant is doing before it writes, or that a conversation is loading. |
|
|
185
|
+
| `ErrorMessage` | `p` | The latest problem, in the visitor's language. |
|
|
186
|
+
|
|
187
|
+
Primitives that have nothing to show render nothing, so you can place them without conditions.
|
|
188
|
+
|
|
189
|
+
**Never render an answer as HTML.** Model output can be steered by whatever the model reads. `MessageText` and `Markdown` turn it into elements without ever producing HTML, allow only `http`, `https` and `mailto` links, and never load images. If you render `message.text` yourself, render it as text.
|
|
190
|
+
|
|
191
|
+
### Hooks
|
|
192
|
+
|
|
193
|
+
- **`useChat()`** returns `{ state, actions, bot, t }` and re-renders on every change.
|
|
194
|
+
- **`useChatState(select)`** returns one value and re-renders only when it changes: `useChatState((state) => state.busy)`. Return a value from the state, not a new object.
|
|
195
|
+
- **`useMessage()`** returns the message being rendered, inside `MessageList`.
|
|
196
|
+
|
|
197
|
+
| `state` | Meaning |
|
|
198
|
+
| --- | --- |
|
|
199
|
+
| `phase` | `'starting'` on the server and until the chat knows the visitor, `'loading'` while a stored conversation loads, then `'ready'`. |
|
|
200
|
+
| `busy` | A turn is under way. |
|
|
201
|
+
| `messages` | Each with `id`, `role`, `text`, `status` (`'streaming'`, `'done'`, `'error'`), `citations`, `files` and `feedback`. |
|
|
202
|
+
| `draft`, `files` | The message field's text and the files picked for the next message. |
|
|
203
|
+
| `error`, `activity` | The latest problem, and what the assistant is doing before it writes. |
|
|
204
|
+
| `dictation`, `elapsed`, `canDictate` | The dictation: `'idle'`, `'recording'` or `'transcribing'`, its seconds, and whether this browser can record. |
|
|
205
|
+
| `ratings`, `commenting` | The visitor's ratings by `message.feedback.key`, and the answer the chat asks about after a 👎. |
|
|
206
|
+
|
|
207
|
+
| `actions` | Meaning |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| `send(text?)` | Sends the draft, or `text` on its own (a suggested question). |
|
|
210
|
+
| `setDraft(text)` | Sets the message field. |
|
|
211
|
+
| `addFiles(files)`, `removeFile(key)` | Files for the next message. |
|
|
212
|
+
| `startDictation()`, `finishDictation()`, `cancelDictation()` | Dictation; finishing puts the transcript into the draft. |
|
|
213
|
+
| `newConversation()` | Deletes the conversation and starts with an empty chat. |
|
|
214
|
+
| `rate(messageId, rating, comment?)`, `dismissComment()` | Ratings: `'up'`, `'down'`, or `null` to take one back. |
|
|
215
|
+
| `focus()` | Moves keyboard focus to the message field. |
|
|
216
|
+
|
|
217
|
+
`bot` holds the bot's public settings in the visitor's language (`title`, `greeting`, `starters`, `placeholder`, `avatar`, `disclosure`, what may be attached). `t(key)` returns any of the chat's [texts](texts.md).
|
|
218
|
+
|
|
219
|
+
## Styling
|
|
220
|
+
|
|
221
|
+
The same tokens and parts as the widget ([Styling](styling.md), [Themes](themes.md)), with three differences inside a page:
|
|
222
|
+
|
|
223
|
+
- **The theme root is an element, not the document.** `Theme` (inside `DefaultChat`) renders `<div data-askdare-root data-ask-bot="support" …>` with the variant attributes. Where the widget's docs say `:root` or `<html>`, read that element.
|
|
224
|
+
- **Your site's CSS reaches the chat.** The chat's styles are in `@layer askdare` and never reach outside the chat. Your own unlayered CSS wins over them, on purpose: `[data-ask-part="bubble"] { border-radius: 6px; }` in your stylesheet just works. A broad rule of your site, such as `button { text-transform: uppercase; }`, applies to the chat's buttons too.
|
|
225
|
+
- **The bot's `widget.css` still applies, scoped to that bot's chat.** `:root` in it means the theme root.
|
|
226
|
+
|
|
227
|
+
### With a CSS reset (Tailwind)
|
|
228
|
+
|
|
229
|
+
A reset written without a layer overrides the chat's layered styles. Put the reset in a layer that comes before `askdare`:
|
|
230
|
+
|
|
231
|
+
```css
|
|
232
|
+
/* Tailwind CSS 4 */
|
|
233
|
+
@layer theme, base, askdare, components, utilities;
|
|
234
|
+
@import "tailwindcss";
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
```css
|
|
238
|
+
/* Tailwind CSS 3 */
|
|
239
|
+
@layer tailwind-base, askdare;
|
|
240
|
+
@layer tailwind-base {
|
|
241
|
+
@tailwind base;
|
|
242
|
+
}
|
|
243
|
+
@tailwind components;
|
|
244
|
+
@tailwind utilities;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
With that order the chat looks the same as without the reset, and your utilities still win over it.
|
|
248
|
+
|
|
249
|
+
## Content Security Policy
|
|
250
|
+
|
|
251
|
+
The widget brings its own policy inside the iframe. A chat inside your page lives under your page's policy, which must allow, all for your own origin:
|
|
252
|
+
|
|
253
|
+
| Directive | Why |
|
|
254
|
+
| --- | --- |
|
|
255
|
+
| `connect-src 'self'` | The chat's requests to the chat route. |
|
|
256
|
+
| `style-src 'self'` | The theme, skin and font stylesheets from the chat route. |
|
|
257
|
+
| `font-src 'self'` | The built-in themes' fonts. |
|
|
258
|
+
| `img-src 'self' blob: data:` | Previews of files the visitor attaches, and a `data:` avatar. |
|
|
259
|
+
| `Permissions-Policy: microphone=(self)` | Dictation, if the bot has voice input. |
|
|
260
|
+
|
|
261
|
+
## Eject the default look
|
|
262
|
+
|
|
263
|
+
When the props and slots of `DefaultChat` aren't enough, copy its source into your app and change it:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npx @boldare/askdare add ui
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
It writes the components and their stylesheet to `components/askdare` and never overwrites a file ([Command line](cli.md#add-ui)). Then change one import:
|
|
270
|
+
|
|
271
|
+
```diff
|
|
272
|
+
- import { DefaultChat } from '@boldare/askdare/react';
|
|
273
|
+
+ import { DefaultChat } from '@/components/askdare';
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The copy imports only `@boldare/askdare/react`, so `Root`, the hooks and the primitives keep coming from the library and keep getting its fixes. The copied files are yours: when a later version changes the default look, the changelog says so, and you take what you want by hand.
|
|
277
|
+
|
|
278
|
+
## Good to know
|
|
279
|
+
|
|
280
|
+
- **Server rendering.** The chat renders on the server in its starting state, with the greeting and suggestions, and connects after hydration. A stored conversation appears then.
|
|
281
|
+
- **Several chats on a page** work, each in its own `Root`, also for different bots with different themes.
|
|
282
|
+
- **One conversation per bot and browser**, shared by every page that shows that bot, and by the widget on the same origin.
|
|
283
|
+
- **Sizes** (gzipped, in your bundle): about 28 KB for everything, about 8 KB when you use only `Root` and the hooks. The Markdown renderer is loaded only if you render `MessageText` or `Markdown`.
|
package/docs/styling.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# Styling and customization
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Five levels, each with more freedom than the last ([ADR-0008](https://github.com/boldare/askdare/blob/main/docs/adr/0008-ui-customization-and-themes.md)). Streaming, security and limits stay in the library whatever you change.
|
|
4
4
|
|
|
5
5
|
| Level | How | For |
|
|
6
6
|
| --- | --- | --- |
|
|
7
7
|
| 1. Configuration | `widget: { … }` in `defineBot` | Texts, language, theme, suggestions, avatar, disclosure |
|
|
8
8
|
| 2. Your own CSS | `widget.css`, plus `::part()` for the launcher | Any look, on top of the parts and tokens below |
|
|
9
9
|
| 3. Page JavaScript | `askdare(…)` and attributes on the script tag | Your own button, the chat inside your page, per-page texts and context |
|
|
10
|
+
| 4. React | `@boldare/askdare/react` | The chat as components of your own Next.js app, with the default look or your own markup: see [React](react.md) |
|
|
11
|
+
| 5. Your copy of the components | `npx @boldare/askdare add ui` | Changing the default components themselves |
|
|
10
12
|
|
|
11
13
|
## 1. Configuration
|
|
12
14
|
|
|
@@ -64,7 +66,7 @@ A full example is the demo site's BLDR theme, in Boldare's style: `defineTheme`
|
|
|
64
66
|
|
|
65
67
|
The launcher's short variables on your page (`--a`, `--o` and the like) are internal too.
|
|
66
68
|
|
|
67
|
-
**Parts** (`[data-ask-part="…"]`, public API): `panel`, `header`, `identity`, `identity-text`, `title`, `subtitle`, `actions`, `new-conversation`, `close`, `avatar`, `orb`, `messages`, `welcome`, `greeting`, `starters`, `starter`, `persona`, `persona-name`, `presence`, `intro`, `intro-card`, `message`, `message-body`, `bubble`, `image-alt`, `typing`, `citations`, `citation`, `attachments-note`, `status`, `error`, `composer`, `composer-box`, `input`, `attach`, `voice`, `send`, `attachments`, `message-attachments`, `attachment`, `attachment-preview`, `attachment-badge`, `attachment-name`, `attachment-status`, `attachment-remove`, `recorder`, `recorder-level`, `recorder-label`, `recorder-time`, `recorder-cancel`, `recorder-done`, `send-label` (shown by Aura), `disclosure`, and the question before a new conversation: `confirm-backdrop`, `confirm`, `confirm-icon`, `confirm-text`, `confirm-actions`, `confirm-cancel`, `confirm-accept`.
|
|
69
|
+
**Parts** (`[data-ask-part="…"]`, public API): `panel`, `header`, `identity`, `identity-text`, `title`, `subtitle`, `actions`, `new-conversation`, `close`, `avatar`, `orb`, `messages`, `welcome`, `greeting`, `starters`, `starter`, `persona`, `persona-name`, `presence`, `intro`, `intro-card`, `message`, `message-body`, `bubble`, `image-alt`, `typing`, `citations`, `citation`, `attachments-note`, the rating of an answer: `feedback`, `feedback-button`, `feedback-comment`, `feedback-comment-input`, `feedback-comment-actions`, `feedback-skip`, `feedback-send`, then `status`, `error`, `composer`, `composer-box`, `input`, `attach`, `voice`, `send`, `attachments`, `message-attachments`, `attachment`, `attachment-preview`, `attachment-badge`, `attachment-name`, `attachment-status`, `attachment-remove`, `recorder`, `recorder-level`, `recorder-label`, `recorder-time`, `recorder-cancel`, `recorder-done`, `send-label` (shown by Aura), `disclosure`, and the question before a new conversation: `confirm-backdrop`, `confirm`, `confirm-icon`, `confirm-text`, `confirm-actions`, `confirm-cancel`, `confirm-accept`.
|
|
68
70
|
|
|
69
71
|
`identity-text` holds the title and subtitle in the header. `image-alt` stands in for an image in a reply: the chat never loads images that the model writes, so it shows their alt text in brackets.
|
|
70
72
|
|
|
@@ -79,6 +81,7 @@ The launcher's short variables on your page (`--a`, `--o` and the like) are inte
|
|
|
79
81
|
| `attachment` | `data-status` | `uploading`, `ready`, `error`, on files not sent yet; absent in sent messages |
|
|
80
82
|
| `attachment` | `data-kind` | `image`, `pdf`; absent until the chat has recognized the file |
|
|
81
83
|
| `recorder` | `data-state` | `recording`, `transcribing` |
|
|
84
|
+
| `feedback-button` | `data-rating` | `up`, `down`; `aria-pressed="true"` on the visitor's rating |
|
|
82
85
|
| `avatar` | `data-kind` | `orb`, `icon`, `initials`, `image` |
|
|
83
86
|
| `avatar` | `data-size` | `small` in the header, next to the assistant's messages and in the `intro` welcome; `large` in the `hero` and `persona` welcome |
|
|
84
87
|
| `welcome` | `data-layout` | `hero`, `persona`, `intro` |
|
|
@@ -170,6 +173,15 @@ An inline chat loads with the page without taking focus or scrolling to itself.
|
|
|
170
173
|
|
|
171
174
|
In a React app, Next.js included, add the script after hydration, for example from a `useEffect` in a small client component. The loader adds the chat inside your element, and React must not find it there while it hydrates. The demo site's [`chat-script.tsx`](https://github.com/boldare/askdare/blob/main/site/app/chat-script.tsx) does this. The chat loads once per page load and lives as long as its element: put the element in a layout that stays, or link to the page with full page loads, because a client-side navigation away and back leaves the element empty.
|
|
172
175
|
|
|
176
|
+
## Inside a page (React)
|
|
177
|
+
|
|
178
|
+
With `@boldare/askdare/react` the chat is part of your page instead of an iframe ([React](react.md)). The tokens, parts and states above are the same. What differs:
|
|
179
|
+
|
|
180
|
+
- **The theme root is an element.** Where this page says `<html>` or `:root`, a chat inside a page has `<div data-askdare-root data-ask-bot="<bot id>">` with the same variant attributes. `:root` in a bot's `widget.css` means that element there, and the rest of `widget.css` applies only inside that bot's chat.
|
|
181
|
+
- **Your site's stylesheet can style the chat directly.** `[data-ask-part="…"]` selectors work from your own CSS, and unlayered rules win over the chat's `@layer askdare`. The chat's own styles never reach outside it.
|
|
182
|
+
- **A CSS reset must be in a layer before `askdare`,** or it overrides the chat. [React](react.md#with-a-css-reset-tailwind) has the lines for Tailwind CSS 3 and 4.
|
|
183
|
+
- **Your page's Content Security Policy applies,** not the iframe's: fonts and images in `widget.css` follow your policy.
|
|
184
|
+
|
|
173
185
|
## Accessibility
|
|
174
186
|
|
|
175
187
|
Accessibility is not configurable away. The focus ring is always visible, motion follows `prefers-reduced-motion`, the chat is a labelled dialog, and Escape closes it (or cancels a dictation). Every preset passes axe in every state, and its colors pass WCAG AA (AAA for text in Care); a customized theme with weak contrast triggers a warning in development.
|
package/docs/support.md
CHANGED
|
@@ -8,7 +8,8 @@ What askdare is tested with and promises to keep working. The reasoning is in [A
|
|
|
8
8
|
| --- | --- | --- |
|
|
9
9
|
| Node.js | 22 and 24 | 20 and older |
|
|
10
10
|
| Next.js | 16.x with the App Router, on the Node.js runtime; Turbopack and `next build --webpack` | Pages Router, Edge runtime, static export |
|
|
11
|
-
| React | 19 | 18 |
|
|
11
|
+
| React | 19 (only for `@boldare/askdare/react`, an optional peer) | 18 |
|
|
12
|
+
| OpenTelemetry | `@opentelemetry/api` 1.3 or later, for `@boldare/askdare-otel` | |
|
|
12
13
|
| zod | 4.1 or later | 3 |
|
|
13
14
|
| TypeScript | 5.9, 6.0 and 7.0 | |
|
|
14
15
|
| Hosting | Vercel and Heroku | Other hosts that run `next start` should work, but aren't tested |
|
|
@@ -32,7 +33,8 @@ Every release is tested in Chromium, Firefox and WebKit: embedding, the page API
|
|
|
32
33
|
| | Gzipped | Budget |
|
|
33
34
|
| --- | --- | --- |
|
|
34
35
|
| The loader (`widget.js`), on every page | about 3 KB | 5 KB |
|
|
35
|
-
| The chat itself, when the visitor opens it | about
|
|
36
|
+
| The chat itself, when the visitor opens it | about 38 KB, plus 6 KB of styles | 50 KB and 8 KB |
|
|
37
|
+
| `@boldare/askdare/react` in your app's bundle, without React itself | about 28 KB; about 8 KB with only `Root` and the hooks | 32 KB and 12 KB |
|
|
36
38
|
| One theme's fonts, from your app | up to 82 KB | 82 KB |
|
|
37
39
|
|
|
38
40
|
The build fails when one of these grows past its budget.
|
package/docs/texts.md
CHANGED
|
@@ -112,6 +112,12 @@ The table is generated from the library's dictionaries with `pnpm --filter @bold
|
|
|
112
112
|
| `status.tool` | Using {name}… | Korzystam z narzędzia {name}… |
|
|
113
113
|
| `status.typing` | The assistant is typing | Asystent pisze |
|
|
114
114
|
| `message.sources` | Sources | Źródła |
|
|
115
|
+
| `feedback.label` | Rate this answer | Oceń tę odpowiedź |
|
|
116
|
+
| `feedback.up` | Helpful | Pomocna |
|
|
117
|
+
| `feedback.down` | Not helpful | Niepomocna |
|
|
118
|
+
| `feedback.comment` | What went wrong? | Co było nie tak? |
|
|
119
|
+
| `feedback.send` | Send feedback | Wyślij opinię |
|
|
120
|
+
| `feedback.skip` | Skip | Pomiń |
|
|
115
121
|
| `message.attachments.zero` | — | — |
|
|
116
122
|
| `message.attachments.one` | {count} attachment | {count} załącznik |
|
|
117
123
|
| `message.attachments.two` | — | — |
|
package/docs/troubleshooting.md
CHANGED
|
@@ -334,6 +334,18 @@ Related errors:
|
|
|
334
334
|
|
|
335
335
|
**To switch back on**, remove the variable or set it to anything else, and restart or redeploy.
|
|
336
336
|
|
|
337
|
+
## No 👍 and 👎 under answers
|
|
338
|
+
|
|
339
|
+
- `createChatHandler` has no `onFeedback`. Without it the buttons don't show, because a rating would have nowhere to go.
|
|
340
|
+
- The bot sets `widget: { feedback: false }`.
|
|
341
|
+
- The answer is still streaming, or it failed. See [Answer ratings](feedback.md).
|
|
342
|
+
|
|
343
|
+
## The chat inside a page is unstyled or has no height
|
|
344
|
+
|
|
345
|
+
- `DefaultChat` fills the element it sits in: give it a height with `className` or `style`.
|
|
346
|
+
- The page's Content Security Policy blocks the chat route's stylesheets or fonts: allow `style-src 'self'` and `font-src 'self'` ([React](react.md#content-security-policy)).
|
|
347
|
+
- A CSS reset in your own stylesheet comes after the chat's: put it in a layer before `askdare` ([React](react.md#with-a-css-reset-tailwind)).
|
|
348
|
+
|
|
337
349
|
## Doctor can't check the app
|
|
338
350
|
|
|
339
351
|
| `doctor` says | Fix |
|
package/llms.txt
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
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
|
|
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.
|
|
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
10
|
- [Configuration](docs/configuration.md): every `defineBot` and `createChatHandler` option, limits with defaults, environment variables
|
|
11
11
|
- [Embedding](docs/embedding.md): the script tag and its `data-*` attributes, several bots, the host page's CSP, staging and production
|
|
12
|
-
- [CLI](docs/cli.md): `init`, `doctor`, `kb sync` and `usage`, with every flag
|
|
12
|
+
- [CLI](docs/cli.md): `init`, `doctor`, `kb sync`, `add ui` and `usage`, with every flag
|
|
13
13
|
- [Troubleshooting](docs/troubleshooting.md): symptoms, causes and fixes, by error code
|
|
14
14
|
- [Tools](docs/tools.md): `defineTool`, Zod schemas, what a tool may trust
|
|
15
15
|
- [Signed-in visitors](docs/identity.md): `askdare('identify')`, IDENTITY_SECRET, `context.identity`
|
|
@@ -17,11 +17,14 @@ Set it up with `npx @boldare/askdare init` and verify it with `npx @boldare/askd
|
|
|
17
17
|
- [Attachments](docs/attachments.md): images and PDFs from visitors
|
|
18
18
|
- [Voice input](docs/voice-input.md): dictation and its limits
|
|
19
19
|
- [Styling](docs/styling.md): texts, languages, AI disclosure, custom CSS, `askdare('open' | 'configure')`, inline mode
|
|
20
|
+
- [React](docs/react.md): the chat inside a page of your own app with `@boldare/askdare/react`: `getChatConfig`, `Root`, `DefaultChat`, hooks and primitives, CSS resets, CSP, `add ui`
|
|
20
21
|
- [Texts](docs/texts.md): every text key with its English and Polish default, plurals, adding a language
|
|
21
22
|
- [Themes](docs/themes.md): Halo, Aura, Sage and Care, tokens and variants
|
|
22
23
|
- [Deployment](docs/deployment.md): Vercel, Heroku, proxies, shared limits
|
|
23
24
|
- [Going public](docs/going-public.md): OpenAI project, secrets, limits, privacy checklist
|
|
24
25
|
- [Costs](docs/costs.md): the worst case under the default limits, and how to keep it bounded
|
|
26
|
+
- [Observability](docs/observability.md): `onUsage` and `onError`, cost per turn, OpenTelemetry spans with `@boldare/askdare-otel`
|
|
27
|
+
- [Answer ratings](docs/feedback.md): 👍/👎 with an optional comment, `onFeedback`, what the report holds
|
|
25
28
|
- [Privacy](docs/privacy.md): what is stored where, for your privacy policy
|
|
26
29
|
- [Support](docs/support.md): Node.js, Next.js, React, zod and TypeScript versions, browsers, sizes
|
|
27
30
|
- [Migrating from @boldare/openai-assistant](docs/migrating-from-openai-assistant.md): what maps to what
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boldare/askdare",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Embeddable AI chatbot for Next.js, built on the official OpenAI SDK.",
|
|
3
|
+
"version": "0.2.0-rc.0",
|
|
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": {
|
|
7
7
|
"name": "Boldare",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"responses-api",
|
|
28
28
|
"rag",
|
|
29
29
|
"openai-assistant",
|
|
30
|
-
"assistants-api"
|
|
30
|
+
"assistants-api",
|
|
31
|
+
"react",
|
|
32
|
+
"headless"
|
|
31
33
|
],
|
|
32
34
|
"type": "module",
|
|
33
35
|
"sideEffects": false,
|
|
@@ -43,6 +45,10 @@
|
|
|
43
45
|
"types": "./dist/next.d.ts",
|
|
44
46
|
"default": "./dist/next.js"
|
|
45
47
|
},
|
|
48
|
+
"./react": {
|
|
49
|
+
"types": "./dist/react.d.ts",
|
|
50
|
+
"default": "./dist/react.js"
|
|
51
|
+
},
|
|
46
52
|
"./package.json": "./package.json"
|
|
47
53
|
},
|
|
48
54
|
"types": "./dist/index.d.ts",
|
|
@@ -65,8 +71,10 @@
|
|
|
65
71
|
"@fontsource-variable/atkinson-hyperlegible-next": "5.3.0",
|
|
66
72
|
"@fontsource-variable/geist": "5.3.0",
|
|
67
73
|
"@fontsource-variable/plus-jakarta-sans": "5.3.0",
|
|
74
|
+
"@testing-library/react": "^16.3.3",
|
|
68
75
|
"@types/react": "^19.3.0",
|
|
69
76
|
"@types/react-dom": "^19.3.0",
|
|
77
|
+
"happy-dom": "^21.0.4",
|
|
70
78
|
"marked": "18.1.3",
|
|
71
79
|
"next": "^16.4.5",
|
|
72
80
|
"preact": "11.1.1",
|
|
@@ -79,11 +87,15 @@
|
|
|
79
87
|
},
|
|
80
88
|
"peerDependencies": {
|
|
81
89
|
"next": "^16.0.0",
|
|
90
|
+
"react": "^19.0.0",
|
|
82
91
|
"zod": "^4.1.0"
|
|
83
92
|
},
|
|
84
93
|
"peerDependenciesMeta": {
|
|
85
94
|
"next": {
|
|
86
95
|
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"react": {
|
|
98
|
+
"optional": true
|
|
87
99
|
}
|
|
88
100
|
},
|
|
89
101
|
"dependencies": {
|
|
@@ -91,10 +103,10 @@
|
|
|
91
103
|
"openai": "^7.52.0"
|
|
92
104
|
},
|
|
93
105
|
"scripts": {
|
|
94
|
-
"build:assets": "vite build -c vite.widget.config.ts && vite build -c vite.loader.config.ts && node scripts/inline-assets.mjs",
|
|
95
|
-
"build": "pnpm run build:assets && tsdown && node scripts/copy-docs.mjs",
|
|
96
|
-
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.browser.json",
|
|
97
|
-
"check:package": "publint --strict && attw --pack . --profile esm-only && node ../../scripts/check-dts-no-leak.mjs dist && node scripts/api-snapshot.mjs && tsc -p types-test",
|
|
106
|
+
"build:assets": "vite build -c vite.widget.config.ts && vite build -c vite.skin.config.ts && vite build -c vite.loader.config.ts && node scripts/inline-assets.mjs",
|
|
107
|
+
"build": "pnpm run build:assets && tsdown && node scripts/copy-ui.mjs && node scripts/copy-docs.mjs",
|
|
108
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.react.json && tsc -p tsconfig.browser.json",
|
|
109
|
+
"check:package": "publint --strict && attw --pack . --profile esm-only && node ../../scripts/check-dts-no-leak.mjs dist && node scripts/api-snapshot.mjs && node scripts/react-size.mjs && tsc -p tsconfig.eject.json && tsc -p types-test",
|
|
98
110
|
"api:update": "node scripts/api-snapshot.mjs --update",
|
|
99
111
|
"docs:texts": "node scripts/docs-texts.ts"
|
|
100
112
|
}
|
package/skills/askdare/SKILL.md
CHANGED
|
@@ -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, themes, knowledge base, 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, themes, knowledge base, answer ratings, usage reports, 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,8 +17,9 @@ 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`.
|
|
20
|
+
- `defineBot`, `defineTool`, `defineTheme` from `@boldare/askdare`; `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
|
+
- 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.
|
|
22
23
|
- Styling: `widget.texts`, `widget.theme`, `widget.css` with `[data-ask-part="…"]` selectors and `--ask-*` tokens (see `docs/styling.md`).
|
|
23
24
|
|
|
24
25
|
Never import from `@boldare/askdare/dist/…` or other internal paths.
|
|
@@ -31,6 +32,9 @@ Never import from `@boldare/askdare/dist/…` or other internal paths.
|
|
|
31
32
|
- Secrets (`OPENAI_API_KEY`, `CHAT_SECRET`) belong in `.env.local` or the host's settings, never in code, instructions or commits. Never print them.
|
|
32
33
|
- Bot instructions must contain no secrets: visitors can make the model repeat them.
|
|
33
34
|
- Sites that embed the chat go in `security.allowedOrigins` as exact origins, without wildcards.
|
|
35
|
+
- With `@boldare/askdare/react`: never render `message.text` as HTML (use `MessageText` or `Markdown`); sign a visitor out with `identity={null}`, since `undefined` keeps the current one; a page that passes `identity` must not be cached; on pages with third-party scripts, prefer the script-tag widget.
|
|
34
36
|
- Tools: every Zod field is required (use `.nullable()`, not `.optional()`). Never take user IDs, emails or permissions from tool arguments; use the verified `context` (`visitorId`, `botId`, `locale`, `identity`, `signal`). Keep tools read-only.
|
|
35
37
|
- Signed-in users: the site's backend signs an HS256 JWT with `IDENTITY_SECRET` (`sub`, `aud` = bot ID, `iat`, `exp`), and the page calls `askdare('identify', token)` (`null` on sign-out). See `docs/identity.md`.
|
|
36
38
|
- More than one server instance (Vercel, several dynos) needs shared limits: `@boldare/askdare-upstash`.
|
|
39
|
+
- 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`.
|
|
40
|
+
- 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`.
|