@boldare/askdare 0.2.0 → 0.3.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 +13 -0
- package/dist/{version.js → define-tool.js} +162 -15
- package/dist/index.js +4 -33
- package/dist/next.js +317 -179
- package/dist/react.d.ts +28 -4
- package/dist/react.js +124 -36
- package/dist/store.d.ts +31 -3
- package/dist/ui/askdare.css +67 -1
- package/dist/ui/avatar.tsx +1 -1
- package/dist/ui/chat.tsx +1 -1
- package/dist/ui/confirm.tsx +1 -1
- package/dist/ui/context.ts +1 -1
- package/dist/ui/feedback.tsx +1 -1
- package/dist/ui/footer.tsx +7 -2
- package/dist/ui/header.tsx +1 -1
- package/dist/ui/icons.tsx +1 -1
- package/dist/ui/index.ts +1 -1
- package/dist/ui/message.tsx +17 -3
- package/dist/ui/panel.tsx +1 -1
- package/dist/ui/welcome.tsx +1 -1
- package/docs/configuration.md +1 -0
- package/docs/costs.md +9 -0
- package/docs/embedding.md +4 -3
- package/docs/events.md +2 -2
- package/docs/feedback.md +116 -0
- package/docs/privacy.md +3 -3
- package/docs/protocol.md +13 -1
- package/docs/react.md +5 -2
- package/docs/reply-options.md +240 -0
- package/docs/styling.md +6 -3
- package/docs/texts.md +97 -0
- package/docs/themes.md +2 -1
- package/docs/tools.md +24 -0
- package/llms.txt +3 -1
- package/package.json +1 -1
- package/skills/askdare/SKILL.md +4 -1
package/docs/texts.md
CHANGED
|
@@ -45,6 +45,102 @@ A page can still set its own greeting with `askdare('configure', { greeting })`;
|
|
|
45
45
|
|
|
46
46
|
With `'auto'`, the launcher on your page follows the same order. Your `instructions` function receives the chosen tag as `context.locale`, so you can tell the model which language to answer in.
|
|
47
47
|
|
|
48
|
+
### Switching the language on the page
|
|
49
|
+
|
|
50
|
+
A site that switches its language without a page load, such as a single-page app with a language menu, can switch the chat too:
|
|
51
|
+
|
|
52
|
+
- **`data-follow-lang`** on the script tag makes the chat follow the page's `<html lang>` whenever it changes.
|
|
53
|
+
- **`askdare('configure', { locale: 'pl' })`** switches it from your own code. It wins over `data-follow-lang` until the page's `lang` changes again.
|
|
54
|
+
|
|
55
|
+
The launcher's texts change at once, and the chat reloads in the new language. The visitor keeps their conversation: earlier answers stay in the language they were written in, and new answers and the interface follow the switch. Your `instructions` function gets the new tag as `context.locale` from the next message on. The reload loads the conversation again, which takes about as long as opening the chat. An answer still streaming disappears from view, and the page hears `message.received` with `outcome: 'stopped'` ([Chat events](events.md)); the server still finishes and stores it.
|
|
56
|
+
|
|
57
|
+
Only a bot with `locale: 'auto'` switches. A bot with a fixed locale keeps its language, and the console says once that it ignored the change. The value is a BCP 47 tag; anything else is ignored with a console warning.
|
|
58
|
+
|
|
59
|
+
**Follow the page's language.** If your i18n library sets `<html lang>` when the visitor switches, add `data-follow-lang` and you're done:
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<script src="https://app.example.com/api/chat/widget.js?bot=support" data-follow-lang async></script>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// Your language menu, or your i18n library, changes the attribute:
|
|
67
|
+
document.documentElement.lang = 'pl';
|
|
68
|
+
// The launcher turns Polish at once, and the chat reloads in Polish.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Setting the same language again does nothing.
|
|
72
|
+
|
|
73
|
+
**Switch from your own code.** Without `data-follow-lang`, or when the page's `lang` doesn't say what the chat should speak, call `configure` from your language menu:
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<select id="language" aria-label="Language">
|
|
77
|
+
<option value="en">English</option>
|
|
78
|
+
<option value="pl">Polski</option>
|
|
79
|
+
</select>
|
|
80
|
+
|
|
81
|
+
<script>
|
|
82
|
+
window.askdare = window.askdare || function () {
|
|
83
|
+
(window.askdare.q = window.askdare.q || []).push(arguments);
|
|
84
|
+
};
|
|
85
|
+
document.getElementById('language').addEventListener('change', function (event) {
|
|
86
|
+
askdare('configure', { locale: event.target.value });
|
|
87
|
+
});
|
|
88
|
+
</script>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
A call with only `locale` keeps the greeting, starters and page context of earlier `configure` calls. Next to `data-follow-lang`, your call wins until the page's `lang` changes again.
|
|
92
|
+
|
|
93
|
+
**In React.** `Root` starts the chat again when the `locale` of its config changes, and the conversation stays ([React](react.md#good-to-know)). Read the language in a Server Component, for example from a `[lang]` segment:
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
// app/[lang]/help/page.tsx
|
|
97
|
+
import { getChatConfig } from '@boldare/askdare/next';
|
|
98
|
+
import { DefaultChat, Root } from '@boldare/askdare/react';
|
|
99
|
+
import { bots } from '@/askdare.config';
|
|
100
|
+
|
|
101
|
+
export default async function HelpPage({ params }: { params: Promise<{ lang: string }> }) {
|
|
102
|
+
const { lang } = await params;
|
|
103
|
+
const config = getChatConfig({ bots, bot: 'support', locale: lang });
|
|
104
|
+
return (
|
|
105
|
+
<Root config={config}>
|
|
106
|
+
<DefaultChat className="help-chat" />
|
|
107
|
+
</Root>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
A link from `/en/help` to `/pl/help` renders the chat in Polish with the same conversation. If the page keeps the language in client state instead, read the config for each language you offer on the server, pass them down, and give `Root` the one that matches:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
'use client';
|
|
116
|
+
import { useState } from 'react';
|
|
117
|
+
import { type ChatConfig, DefaultChat, Root } from '@boldare/askdare/react';
|
|
118
|
+
|
|
119
|
+
export function HelpChat({ configs }: { configs: Record<'en' | 'pl', ChatConfig> }) {
|
|
120
|
+
const [lang, setLang] = useState<'en' | 'pl'>('en');
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<button type="button" onClick={() => setLang(lang === 'en' ? 'pl' : 'en')}>
|
|
124
|
+
{lang === 'en' ? 'Polski' : 'English'}
|
|
125
|
+
</button>
|
|
126
|
+
<Root config={configs[lang]}>
|
|
127
|
+
<DefaultChat className="help-chat" />
|
|
128
|
+
</Root>
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
// In the Server Component that renders it:
|
|
136
|
+
<HelpChat
|
|
137
|
+
configs={{
|
|
138
|
+
en: getChatConfig({ bots, bot: 'support', locale: 'en' }),
|
|
139
|
+
pl: getChatConfig({ bots, bot: 'support', locale: 'pl' }),
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
```
|
|
143
|
+
|
|
48
144
|
## Plurals
|
|
49
145
|
|
|
50
146
|
A text with a number has one key per plural category: `zero`, `one`, `two`, `few`, `many` and `other`, the categories `Intl.PluralRules` uses. `message.attachments` is such a text: after a page reload, the chat shows it under each message that had files.
|
|
@@ -112,6 +208,7 @@ The table is generated from the library's dictionaries with `pnpm --filter @bold
|
|
|
112
208
|
| `status.tool` | Using {name}… | Korzystam z narzędzia {name}… |
|
|
113
209
|
| `status.typing` | The assistant is typing | Asystent pisze |
|
|
114
210
|
| `message.sources` | Sources | Źródła |
|
|
211
|
+
| `message.replies` | Suggested replies | Proponowane odpowiedzi |
|
|
115
212
|
| `feedback.label` | Rate this answer | Oceń tę odpowiedź |
|
|
116
213
|
| `feedback.up` | Helpful | Pomocna |
|
|
117
214
|
| `feedback.down` | Not helpful | Niepomocna |
|
package/docs/themes.md
CHANGED
|
@@ -27,7 +27,7 @@ defineBot({
|
|
|
27
27
|
|
|
28
28
|
`starters` are clickable suggestions (up to 4). `avatar` is the assistant's picture: a path on your app such as `/avatar.png`, or a small PNG, JPEG, WebP or GIF data URL. `launcherLabel` is the text of the pill launcher (default "Ask us").
|
|
29
29
|
|
|
30
|
-
To compare them, run the demo site from the repository (`site/`) with `ASKDARE_GALLERY=1` and open `/gallery`: every state of the widget (welcome, conversation, streaming, attachments, error, listening) in any preset, scheme and width. The site's home page shows the same assistant in each preset: switch the theme and show the chat as a bubble or inside the page.
|
|
30
|
+
To compare them, run the demo site from the repository (`site/`) with `ASKDARE_GALLERY=1` and open `/gallery`: every state of the widget (welcome, conversation, streaming, attachments, error, listening, ratings, reply options in both places) in any preset, scheme and width. The site's home page shows the same assistant in each preset: switch the theme and show the chat as a bubble or inside the page.
|
|
31
31
|
|
|
32
32
|
## Adjust a preset
|
|
33
33
|
|
|
@@ -79,6 +79,7 @@ CSS values (`backdrop`, `orb`) may not contain `url()`, braces, semicolons or ba
|
|
|
79
79
|
| `surface` | `solid`, `glass` |
|
|
80
80
|
| `density` | `comfortable`, `compact` |
|
|
81
81
|
| `composer` | `outline`, `gradient` |
|
|
82
|
+
| `replies` | `answer` (default): the latest answer's [reply options](reply-options.md) under it; `composer`: in one row above the message field that scrolls sideways |
|
|
82
83
|
|
|
83
84
|
Variants are set as attributes on the iframe document (`data-ask-welcome="persona"` and so on), so your own CSS can target them too.
|
|
84
85
|
|
package/docs/tools.md
CHANGED
|
@@ -40,6 +40,29 @@ defineBot({
|
|
|
40
40
|
|
|
41
41
|
A bot makes at most `limits.maxSteps` model calls per message (default 5); the last one must answer in words.
|
|
42
42
|
|
|
43
|
+
## Reply options
|
|
44
|
+
|
|
45
|
+
A tool can turn its result into options the visitor clicks instead of typing, shown as buttons under the answer. You decide them in code, so they are the same every time the result is:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
export const orderStatus = defineTool({
|
|
49
|
+
name: 'get_order_status',
|
|
50
|
+
// … description, input and execute as above
|
|
51
|
+
replies: (order) =>
|
|
52
|
+
order.status === 'shipped'
|
|
53
|
+
? ['Track the parcel', 'Cancel the order', 'Talk to a person']
|
|
54
|
+
: undefined,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- `replies` gets the result of a successful call, typed from `execute`. It's the result as the model received it, parsed back from JSON (a `Date` is a string by then), so the options come back the same after a reload. A call that failed, timed out or returned too much data defines none.
|
|
59
|
+
- A click sends the option's text as the visitor's own message, exactly as if they had typed it. It doesn't run the tool or anything else by itself: the model reads the message and decides, as always. So write options the visitor would say ("Track the parcel"), not commands.
|
|
60
|
+
- The model never sees the options, and the visitor never sees the result: only the options reach the browser.
|
|
61
|
+
- askdare keeps at most 4 options of up to 80 characters, one line of plain text each, and drops the rest: empty, repeated or too long ones, any with invisible characters, and any that contain a link or something that looks like one (`example.com`). Return `undefined` or `[]` to offer none. If `replies` throws, the answer comes without options and the error is logged.
|
|
62
|
+
- Only the latest answer shows options, and they disappear once the visitor sends anything. When several calls in one answer define options, the last call's win.
|
|
63
|
+
|
|
64
|
+
[Reply options](reply-options.md) has more flows, options in several languages, and when to let the model suggest options instead.
|
|
65
|
+
|
|
43
66
|
## Rules
|
|
44
67
|
|
|
45
68
|
- **Every field is required.** OpenAI's strict mode demands it: use `.nullable()` instead of `.optional()`. `defineTool` fails at startup otherwise.
|
|
@@ -48,5 +71,6 @@ A bot makes at most `limits.maxSteps` model calls per message (default 5); the l
|
|
|
48
71
|
- **Read-only, for now.** Tools that change data (place an order, send an email) need the visitor's confirmation, which askdare doesn't offer yet. Keep tools to lookups.
|
|
49
72
|
- **Keep results small.** Return the fields the model needs. Large results cost input tokens on every later message.
|
|
50
73
|
- **Keep it under about 20 tools per bot.** More tools make the model slower and less accurate.
|
|
74
|
+
- **Reserved names.** `file_search` (the knowledge base) and `suggest_replies` (reply options, `widget.replies: 'suggest'`) are built in; `defineBot` refuses a tool with either name. `suggest_replies` runs none of your code and shows no status to the visitor.
|
|
51
75
|
|
|
52
76
|
The demo site has two working examples in [`site/tools.ts`](https://github.com/boldare/askdare/blob/main/site/tools.ts).
|
package/llms.txt
CHANGED
|
@@ -12,18 +12,20 @@ Set it up with `npx @boldare/askdare init` and verify it with `npx @boldare/askd
|
|
|
12
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
|
+
- [Reply options](docs/reply-options.md): clickable answers under the latest reply, suggested by the model (`widget.replies: 'suggest'`) or defined by a tool (`defineTool({ replies })`), limits, placement, cost
|
|
15
16
|
- [Signed-in visitors](docs/identity.md): `askdare('identify')`, IDENTITY_SECRET, `context.identity`
|
|
16
17
|
- [Knowledge base](docs/knowledge-base.md): `npx @boldare/askdare kb sync`, vector stores, citations
|
|
17
18
|
- [Attachments](docs/attachments.md): images and PDFs from visitors
|
|
18
19
|
- [Voice input](docs/voice-input.md): dictation and its limits
|
|
19
20
|
- [Styling](docs/styling.md): texts, languages, AI disclosure, custom CSS, `askdare('open' | 'configure')`, inline mode
|
|
20
21
|
- [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`
|
|
21
|
-
- [Texts](docs/texts.md): every text key with its English and Polish default, plurals, adding a language
|
|
22
|
+
- [Texts](docs/texts.md): every text key with its English and Polish default, plurals, adding a language, switching the chat's language on the page (`askdare('configure', { locale })`, `data-follow-lang`)
|
|
22
23
|
- [Themes](docs/themes.md): Halo, Aura, Sage and Care, tokens and variants
|
|
23
24
|
- [Deployment](docs/deployment.md): Vercel, Heroku, proxies, shared limits
|
|
24
25
|
- [Going public](docs/going-public.md): OpenAI project, secrets, limits, privacy checklist
|
|
25
26
|
- [Costs](docs/costs.md): the worst case under the default limits, and how to keep it bounded
|
|
26
27
|
- [Observability](docs/observability.md): `onUsage` and `onError`, cost per turn, OpenTelemetry spans with `@boldare/askdare-otel`
|
|
28
|
+
- [Chat events](docs/events.md): what the chat reports to the page, for analytics
|
|
27
29
|
- [Answer ratings](docs/feedback.md): 👍/👎 with an optional comment, `onFeedback`, what the report holds
|
|
28
30
|
- [Privacy](docs/privacy.md): what is stored where, for your privacy policy
|
|
29
31
|
- [Support](docs/support.md): Node.js, Next.js, React, zod and TypeScript versions, browsers, sizes
|
package/package.json
CHANGED
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, 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.
|
|
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, reply options, the chat's language, answer ratings, usage reports, deployment). Use when the project depends on @boldare/askdare or the user asks for a website chatbot built on it.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# askdare
|
|
@@ -19,6 +19,8 @@ description: Add, configure or troubleshoot the @boldare/askdare AI chat in a Ne
|
|
|
19
19
|
|
|
20
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's language on the page, for a bot with `locale: 'auto'`: `askdare('configure', { locale: 'pl' })`, or `data-follow-lang` on the script tag to follow `<html lang>`. The chat reloads in the new language and keeps the conversation; your `instructions` get it as `context.locale`. See `docs/texts.md`.
|
|
23
|
+
- Reply options (clickable answers under the latest reply): `widget.replies: 'suggest'` lets the model suggest them; `defineTool({ replies: (result) => [...] })` derives them from a tool's result. See `docs/reply-options.md`.
|
|
22
24
|
- The chat inside a page of the same Next.js app (React 19): `getChatConfig` from `@boldare/askdare/next` in a Server Component, then `Root`, `DefaultChat`, the hooks (`useChat`, `useChatState`, `useMessage`) and the primitives from `@boldare/askdare/react` (see `docs/react.md`). To change the default components, run `npx @boldare/askdare add ui`; don't copy them from `node_modules` by hand.
|
|
23
25
|
- Styling: `widget.texts`, `widget.theme`, `widget.css` with `[data-ask-part="…"]` selectors and `--ask-*` tokens (see `docs/styling.md`).
|
|
24
26
|
|
|
@@ -35,6 +37,7 @@ Never import from `@boldare/askdare/dist/…` or other internal paths.
|
|
|
35
37
|
- 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.
|
|
36
38
|
- 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.
|
|
37
39
|
- 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`.
|
|
40
|
+
- Reply options: at most 4, up to 80 characters each, plain text without links; anything else is dropped. A click only sends the option's text as the visitor's message, so write options the way a visitor would say them ("Cancel the order"), never as commands or IDs, and never treat a clicked option as more trusted than typed text.
|
|
38
41
|
- More than one server instance (Vercel, several dynos) needs shared limits: `@boldare/askdare-upstash`.
|
|
39
42
|
- 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
43
|
- 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`.
|