@boldare/askdare 0.2.0 → 0.3.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 +34 -0
- package/README.md +1 -1
- 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 +10 -1
- 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/dist/ui/panel.tsx
CHANGED
package/dist/ui/welcome.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
|
|
2
2
|
import { useChat } from '@boldare/askdare/react';
|
|
3
3
|
import type { ReactElement, ReactNode } from 'react';
|
|
4
4
|
import { Avatar } from './avatar';
|
package/docs/configuration.md
CHANGED
|
@@ -208,6 +208,7 @@ Everything in `widget` is sent to browsers. Never put secrets in it. [Styling](s
|
|
|
208
208
|
| `disclosure` | `false \| { privacyUrl?: string }` | shown, no link | The note that visitors talk to an AI. `privacyUrl` is an `https://` URL or a path on your app, such as `/privacy`. `false` hides the note. |
|
|
209
209
|
| `starters` | `string[]` | `[]` | Suggested questions on the welcome screen. Up to 4, 1–80 characters each. |
|
|
210
210
|
| `feedback` | `boolean` | `true` | 👍/👎 under each answer, with an optional comment after 👎. They show only when `createChatHandler` has [`onFeedback`](#onfeedback); `false` hides them for this bot. |
|
|
211
|
+
| `replies` | `'suggest' \| 'off'` | `'off'` | `'suggest'` lets the model offer 2–4 replies under an answer, which visitors click instead of typing ([Reply options](reply-options.md)). It adds the built-in tool `suggest_replies`, so it costs tokens ([Costs](costs.md#reply-options)). Only the server reads it. |
|
|
211
212
|
| `avatar` | `string` | none | A path on your app, such as `/avatar.png`, or a PNG, JPEG, WebP or GIF `data:` URL of up to 90,000 base64 characters. |
|
|
212
213
|
| `theme` | `PresetName \| ThemeDefinition` | `'aura'` | `'halo'`, `'aura'`, `'sage'`, `'care'`, or a theme from `defineTheme`. |
|
|
213
214
|
| `colorScheme` | `'auto' \| 'light' \| 'dark'` | `'auto'` | `'auto'` follows the visitor's system setting. |
|
package/docs/costs.md
CHANGED
|
@@ -155,7 +155,7 @@ A conversation is stored by OpenAI, and every message sends the whole conversati
|
|
|
155
155
|
|
|
156
156
|
- `maxTurns` (default 50) ends a conversation: the visitor is asked to start a new one.
|
|
157
157
|
- askdare sends `truncation: 'auto'`. When a conversation outgrows the model's context window, OpenAI drops the oldest items instead of failing.
|
|
158
|
-
- askdare doesn't compact or summarize conversations
|
|
158
|
+
- 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
159
|
- 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
160
|
|
|
161
161
|
## Prompt caching
|
|
@@ -168,6 +168,15 @@ OpenAI caches the beginning of prompts automatically on supported models, and ca
|
|
|
168
168
|
|
|
169
169
|
askdare's budgets count cached tokens in full, so they overestimate the cost when caching works. OpenAI's [prompt caching guide](https://developers.openai.com/api/docs/guides/prompt-caching) lists the minimum prompt length that can be cached.
|
|
170
170
|
|
|
171
|
+
## Reply options
|
|
172
|
+
|
|
173
|
+
With `widget.replies: 'suggest'`, the model can offer clickable replies under an answer ([Reply options](reply-options.md)). That costs tokens in two ways:
|
|
174
|
+
|
|
175
|
+
- **The tool's definition is input on every model call:** about 250 tokens, estimated from its length. It sits in the stable part of the prompt, so on models with prompt caching it is mostly billed as cached input after the first message.
|
|
176
|
+
- **Sometimes one more model call.** When the model suggests replies after writing its answer, the server answers the call itself and the message ends: no extra call. When it suggests them before answering (or marks its text as an intermediate update, as GPT-5.4 and later can before a tool call), the message takes one more call. That call reads the whole conversation again (mostly cached input) and adds the latency of one request. The options themselves are a few dozen output tokens.
|
|
177
|
+
|
|
178
|
+
The extra call counts against `maxSteps` and the budgets like a tool round: askdare reserves it before each call that may suggest replies, and when a budget can't hold it, or on a bot with `maxSteps: 1`, the model answers without options. Compare `steps` and the tokens in [`onUsage`](configuration.md#onusage) with and without the setting to see what it costs with your model and traffic.
|
|
179
|
+
|
|
171
180
|
## Knowledge base
|
|
172
181
|
|
|
173
182
|
- `knowledge.maxResults` (default 5) is how many chunks the model reads per search. askdare reserves 800 tokens per chunk, 4,000 per message by default.
|
package/docs/embedding.md
CHANGED
|
@@ -18,11 +18,11 @@ The site must be in the bot's `security.allowedOrigins`. Pages of the app itself
|
|
|
18
18
|
|
|
19
19
|
Load it as a plain script. Don't add `type="module"`, `crossorigin` or `integrity`: the loader finds its settings through its own `<script>` tag, and `widget.js` is served without CORS headers.
|
|
20
20
|
|
|
21
|
-
The loader passes the `lang` of the page's `<html>` to the chat. A bot with `locale: 'auto'` follows it; see [Styling](styling.md#1-configuration).
|
|
21
|
+
The loader passes the `lang` of the page's `<html>` to the chat. A bot with `locale: 'auto'` follows it; see [Styling](styling.md#1-configuration). To follow later changes of `lang` too, add `data-follow-lang`.
|
|
22
22
|
|
|
23
23
|
## Script tag attributes
|
|
24
24
|
|
|
25
|
-
The loader reads these
|
|
25
|
+
The loader reads these five attributes from its own `<script>` tag, and no others:
|
|
26
26
|
|
|
27
27
|
| Attribute | Value | Effect |
|
|
28
28
|
| --- | --- | --- |
|
|
@@ -30,6 +30,7 @@ The loader reads these four attributes from its own `<script>` tag, and no other
|
|
|
30
30
|
| `data-mode` | `inline` | The chat fills the element that `data-target` names instead of floating over the page. Any other value is ignored. |
|
|
31
31
|
| `data-target` | A CSS selector, such as `#chat` | The element for an inline chat. Read only with `data-mode="inline"`. |
|
|
32
32
|
| `data-launcher` | `none` | No chat button. Open the chat from your own button with `askdare('open')`. Ignored for an inline chat. |
|
|
33
|
+
| `data-follow-lang` | No value | The chat follows the page's `<html lang>` when it changes, for a site that switches language without a page load. Only for a bot with `locale: 'auto'`; see [Texts](texts.md#switching-the-language-on-the-page). |
|
|
33
34
|
|
|
34
35
|
An inline chat waits until the page has parsed its target element, so the script can sit in `<head>`. When no element matches the selector, the console says `[askdare] No element matches #chat.` and the chat floats instead. Without `data-target`, it floats too.
|
|
35
36
|
|
|
@@ -257,4 +258,4 @@ ASKDARE_ALLOWED_ORIGINS=http://127.0.0.1:4000
|
|
|
257
258
|
|
|
258
259
|
## Page JavaScript
|
|
259
260
|
|
|
260
|
-
The page can open and close the chat, sign the visitor in, and set a greeting, suggestions
|
|
261
|
+
The page can open and close the chat, sign the visitor in, and set a greeting, suggestions, page context and the language per page: `askdare('open')`, `askdare('close')`, `askdare('toggle')`, `askdare('identify', token)` and `askdare('configure', { … })`. See [Styling](styling.md#3-page-javascript) and [Signed-in visitors](identity.md). To hear what happens in the chat, for analytics, use `askdare('on', type, listener)`: see [Chat events](events.md).
|
package/docs/events.md
CHANGED
|
@@ -72,8 +72,8 @@ Every event has `type` and `bot`, the bot's ID. The other fields depend on the t
|
|
|
72
72
|
| --- | --- | --- |
|
|
73
73
|
| `length` | number | The message's length in characters. |
|
|
74
74
|
| `attachments` | number | How many images and PDFs it carried. |
|
|
75
|
-
| `source` | `'typed'` or `'
|
|
76
|
-
| `outcome` | `'completed'`, `'failed'` or `'stopped'` | `stopped` when the chat was taken down mid-answer, as when a React `Root` unmounts. |
|
|
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. |
|
|
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
|
@@ -47,6 +47,122 @@ A 👎 arrives at once, and the comment follows as a second report for the same
|
|
|
47
47
|
- Ratings are limited to 20 a minute per visitor.
|
|
48
48
|
- A comment is text a visitor typed. Treat it like a message: cover it in your privacy notice, and escape it wherever you show it. See [Privacy](privacy.md).
|
|
49
49
|
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
Each report holds the rating, the visitor's comment if they wrote one, the bot, a pseudonym of the visitor, the signed-in user if there is one, and the OpenAI IDs of the conversation and the answer. It never holds the question or the answer: to read those, fetch the conversation with your OpenAI key.
|
|
53
|
+
|
|
54
|
+
Two parts need care wherever you send them:
|
|
55
|
+
- **`comment` and `identity` are personal data.** Keep them where you keep other visitor data, and never write the report to your logs as a whole.
|
|
56
|
+
- **`conversationId` and `itemId` lead to the whole conversation** for anyone with your OpenAI key. Keep them out of logs and analytics too.
|
|
57
|
+
|
|
58
|
+
### Post each 👎 with a comment to Slack
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// app/api/chat/[...path]/route.ts
|
|
62
|
+
// Slack reads <, > and & as markup: escaped, a comment can't add links or @channel.
|
|
63
|
+
const escape = (text: string) =>
|
|
64
|
+
text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
65
|
+
|
|
66
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
67
|
+
bots,
|
|
68
|
+
onFeedback: async ({ bot, rating, comment, conversationId, itemId }) => {
|
|
69
|
+
const webhook = process.env.SLACK_FEEDBACK_WEBHOOK;
|
|
70
|
+
if (!webhook || rating !== 'down' || comment === undefined) return;
|
|
71
|
+
const response = await fetch(webhook, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: { 'Content-Type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
text: `👎 on *${bot}*\n>${escape(comment)}\nConversation \`${conversationId}\`, answer \`${itemId}\``,
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) throw new Error(`Slack answered ${response.status}`);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- **Only reports with a comment.** A 👎 arrives first without one, and its comment follows as a second report. Posting every 👎 would post most of them twice, or with nothing to read. Count the bare ones [below](#count-ratings-next-to-onusage).
|
|
84
|
+
- **Slack now holds visitors' comments.** Name it in your privacy notice, and post to a channel that only the people who review answers can read.
|
|
85
|
+
- **The webhook URL is a secret.** Keep it in an environment variable, never in `widget`.
|
|
86
|
+
- **A failed post doesn't reach the chat.** askdare logs the error's name, not its message, so the comment stays out of your logs.
|
|
87
|
+
|
|
88
|
+
### Store ratings in your database
|
|
89
|
+
|
|
90
|
+
Keep one row per answer and let a later report replace the earlier one: the comment that follows a 👎, a changed mind, a rating taken back. In Postgres:
|
|
91
|
+
|
|
92
|
+
```sql
|
|
93
|
+
create table chat_ratings (
|
|
94
|
+
conversation_id text not null,
|
|
95
|
+
item_id text not null,
|
|
96
|
+
bot text not null,
|
|
97
|
+
visitor text not null,
|
|
98
|
+
rating text, -- 'up', 'down', or null when taken back
|
|
99
|
+
comment text,
|
|
100
|
+
updated_at timestamptz not null default now(),
|
|
101
|
+
primary key (conversation_id, item_id)
|
|
102
|
+
);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// app/api/chat/[...path]/route.ts
|
|
107
|
+
import { sql } from '@/lib/db'; // your Postgres client, such as `postgres` or `@vercel/postgres`
|
|
108
|
+
|
|
109
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
110
|
+
bots,
|
|
111
|
+
onFeedback: async ({ bot, rating, comment, visitor, conversationId, itemId }) => {
|
|
112
|
+
await sql`
|
|
113
|
+
insert into chat_ratings (conversation_id, item_id, bot, visitor, rating, comment)
|
|
114
|
+
values (${conversationId}, ${itemId}, ${bot}, ${visitor}, ${rating}, ${comment ?? null})
|
|
115
|
+
on conflict (conversation_id, item_id) do update
|
|
116
|
+
set rating = excluded.rating, comment = excluded.comment, updated_at = now()`;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- **Query parameters, not string concatenation.** A comment is untrusted text.
|
|
122
|
+
- **Keep comments no longer than you need.** Clear them on a schedule, for example `update chat_ratings set comment = null where updated_at < now() - interval '90 days'`.
|
|
123
|
+
- **Review the 👎 answers** in an internal tool of yours: read the conversation with `openai.conversations.items.list(conversationId)` and find the answer by `itemId`. Never show that tool to visitors.
|
|
124
|
+
- **Sum them up** with `select bot, rating, count(*) from chat_ratings group by bot, rating`.
|
|
125
|
+
|
|
126
|
+
### Count ratings next to `onUsage`
|
|
127
|
+
|
|
128
|
+
To watch the share of 👍 and 👎 on a dashboard, count ratings where you already count turns ([Observability](observability.md)):
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
132
|
+
bots,
|
|
133
|
+
onUsage: async ({ bot, outcome }) => {
|
|
134
|
+
await metrics.increment('chat.turns', { bot, outcome });
|
|
135
|
+
},
|
|
136
|
+
onFeedback: async ({ bot, rating, comment }) => {
|
|
137
|
+
if (comment !== undefined) return; // the comment of a 👎 that was already counted
|
|
138
|
+
await metrics.increment('chat.ratings', { bot, rating: rating ?? 'withdrawn' });
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`chat.ratings` divided by completed `chat.turns` is how often visitors rate; `down` divided by all ratings is how often they're unhappy. The counts are close, not exact: a visitor who changes their mind counts twice, and a rating taken back counts as `withdrawn`. For exact numbers, use the table above.
|
|
144
|
+
|
|
145
|
+
`visitor` is the same pseudonym in both reports, so you can also line ratings up with the cost of the same visitor's turns, without knowing who they are.
|
|
146
|
+
|
|
147
|
+
With `otelUsage()` from `@boldare/askdare-otel`, use an OpenTelemetry counter beside it:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { otelUsage } from '@boldare/askdare-otel';
|
|
151
|
+
import { metrics } from '@opentelemetry/api';
|
|
152
|
+
|
|
153
|
+
const ratings = metrics.getMeter('my-site').createCounter('chat.ratings');
|
|
154
|
+
|
|
155
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
156
|
+
bots,
|
|
157
|
+
onUsage: otelUsage(),
|
|
158
|
+
onFeedback: ({ bot, rating, comment }) => {
|
|
159
|
+
if (comment === undefined) ratings.add(1, { bot, rating: rating ?? 'withdrawn' });
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
To do several of these, call them one after another in a single `onFeedback`.
|
|
165
|
+
|
|
50
166
|
## Texts and styling
|
|
51
167
|
|
|
52
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)).
|
package/docs/privacy.md
CHANGED
|
@@ -49,7 +49,7 @@ After the visitor's first message, the chat writes an entry to `localStorage` fo
|
|
|
49
49
|
| Purpose | To show the visitor's ratings again after a reload |
|
|
50
50
|
| Lifetime | The latest hundred ratings are kept; taking a rating back removes it. It isn't sent to the server: the server keeps no ratings at all |
|
|
51
51
|
|
|
52
|
-
Everything else stays in memory and disappears with the page: the session token, which lasts 15 minutes, and a signed-in visitor's identity.
|
|
52
|
+
Everything else stays in memory and disappears with the page: the session token, which lasts 15 minutes, and a signed-in visitor's identity. The chat's language, set with `askdare('configure', { locale })` or `data-follow-lang`, isn't stored either: the page sets it again on every load ([Texts](texts.md)).
|
|
53
53
|
|
|
54
54
|
The chat sets no cookies. Browsers may partition or block storage in iframes from other sites; then the conversation doesn't survive a reload, and the chat still works. There is no setting to turn the conversation entry off; ratings go with `onFeedback`.
|
|
55
55
|
|
|
@@ -106,13 +106,13 @@ Everything below lives in the OpenAI project whose key the app uses. Name OpenAI
|
|
|
106
106
|
- Your instructions for that request, with whatever you put in them, such as a signed-in user's name.
|
|
107
107
|
- The visitor's message, and the page context from `askdare('configure')` if the bot has `pageContext: true`.
|
|
108
108
|
- Attached files, by reference.
|
|
109
|
-
- Your tools' definitions and, when the model calls them, their results.
|
|
109
|
+
- Your tools' definitions and, when the model calls them, their results. With `widget.replies: 'suggest'`, also the definition of the built-in `suggest_replies` tool, which holds no personal data.
|
|
110
110
|
- The `safety_identifier`, and `prompt_cache_key: "askdare:<bot id>"`, which holds no personal data.
|
|
111
111
|
|
|
112
112
|
### Conversations
|
|
113
113
|
|
|
114
114
|
- Conversations are stored with OpenAI's Conversations API, in your project, **until they are deleted** ([ADR-0003](https://github.com/boldare/askdare/blob/main/docs/adr/0003-conversation-state.md)). Each one carries the bot ID and the visitor ID as metadata (`askdare_bot`, `askdare_visitor`).
|
|
115
|
-
- A conversation holds the visitor's messages, the page context, the answers, and the tool calls with their results. The instructions are sent with each request rather than stored in the conversation.
|
|
115
|
+
- A conversation holds the visitor's messages, the page context, the answers, and the tool calls with their results. [Reply options](reply-options.md) the model suggested are stored there as a call of `suggest_replies`; options a tool defines aren't stored on their own, since they are derived again from the stored result. A clicked option is an ordinary visitor message. The instructions are sent with each request rather than stored in the conversation.
|
|
116
116
|
- **The visitor can delete it.** "Start a new conversation" asks "Start a new conversation? The current one will be deleted." and then deletes it at OpenAI. For bots with attachments, the files attached in it are deleted too; a file that fails to delete expires on its own.
|
|
117
117
|
- **Nothing else deletes it.** When the browser's handle expires after 30 days, or the visitor clears the browser, the conversation stays in your project. askdare keeps no list of conversations, and OpenAI's API has no endpoint to list them, so there is no tool to find, export or delete one visitor's conversation. Take this into account in your retention decision ([Going public](going-public.md#6-privacy-and-transparency)).
|
|
118
118
|
- **Who can read it:** whoever uses the same browser can continue an anonymous conversation and see its history while the handle works. On a shared computer, that includes the next person, unless the visitor started a new conversation. A conversation started while signed in is shown only to that user ([Signed-in visitors](identity.md)).
|
package/docs/protocol.md
CHANGED
|
@@ -24,7 +24,7 @@ Every path sits under the route's base path: `/api/chat` by default, or `basePat
|
|
|
24
24
|
| `POST /doctor` | Doctor token | Checks the setup for `askdare doctor` ([Diagnostics](#diagnostics)) |
|
|
25
25
|
|
|
26
26
|
- **`POST /messages`** takes `{ "botId", "text", "resumeToken"?, "attachments"?, "context"?, "locale"? }`. Without `resumeToken`, the server starts a new conversation and sends `conversation.created`. `locale` is the visitor's language tag, passed to the bot's instructions.
|
|
27
|
-
- **`POST /history`** takes `{ "botId", "resumeToken" }` and answers `{ "messages": [{ "id", "role", "text", "citations", "attachments", "feedback"? }] }`, where `attachments` is a count
|
|
27
|
+
- **`POST /history`** takes `{ "botId", "resumeToken" }` and answers `{ "messages": [{ "id", "role", "text", "citations", "attachments", "feedback"?, "replies"? }] }`, where `attachments` is a count, `feedback` is the answer's rating handle (see [Feedback](#feedback)) and `replies` are the options of the latest answer (see [Reply options](#reply-options)).
|
|
28
28
|
- **`DELETE /conversation`** takes the same body and answers `204` with no body.
|
|
29
29
|
- **Same origin only.** Every `POST` and `DELETE` except `/doctor` refuses cross-site requests with `401`. The API serves the chat's own iframe, which runs on the same origin.
|
|
30
30
|
|
|
@@ -52,6 +52,7 @@ Every path sits under the route's base path: `/api/chat` by default, or `basePat
|
|
|
52
52
|
| `text.delta` | `messageId`, `delta` | Append text to the reply (markdown) |
|
|
53
53
|
| `citation` | `messageId`, `index`, `title`, `url?` | Source for marker `[index]`; `url` is http(s) only |
|
|
54
54
|
| `tool.status` | `messageId`, `callId`, `name`, `state: running \| done \| error` | A tool ran; arguments and results stay on the server. `name: file_search` is the knowledge base search |
|
|
55
|
+
| `replies` | `messageId`, `items` | Options the visitor can click instead of typing ([Reply options](#reply-options)); at most once, before `message.end` |
|
|
55
56
|
| `message.end` | `messageId`, `reason`, `resumeToken?`, `feedback?` | The reply finished. A resumed conversation gets a fresh `resumeToken`, so it stays reachable 30 days after its last message. `feedback` is the answer's rating handle, when answers can be rated. Reasons: `completed`, `max_steps`, `max_output_tokens`, `timeout`, `content_filter`, `aborted` |
|
|
56
57
|
| `error` | `code`, `message`, `retryAfterMs?`, `key?`, `params?` | The turn failed; `message` is safe to show ([keys and parameters](#error-keys-and-parameters)) |
|
|
57
58
|
|
|
@@ -77,6 +78,17 @@ When the app sets `onFeedback` and the bot allows it, every answer comes with a
|
|
|
77
78
|
|
|
78
79
|
`POST /feedback` takes `{ "botId", "feedback", "rating", "comment"? }` with the `Bearer` token, where `feedback` is the `handle`, `rating` is `"up"`, `"down"` or `null` to take a rating back, and `comment` holds at most 500 characters. It answers `204` with no body. A handle of another visitor, another bot or a forged one answers `404`, as does a bot whose answers can't be rated. Ratings are limited per visitor (`429`).
|
|
79
80
|
|
|
81
|
+
## Reply options
|
|
82
|
+
|
|
83
|
+
An answer can offer a few options the visitor clicks instead of typing ("Yes, book it", "Show prices"). With `widget.replies: 'suggest'`, the model suggests them through the built-in tool `suggest_replies`, and the server answers that call itself. They come in a `replies` event, `{ "messageId", "items": ["…"] }`, sent at most once per answer, before its `message.end`. After a reload, `POST /history` returns them as `replies` on the latest answer, as long as the visitor hasn't written since ([ADR-0015](https://github.com/boldare/askdare/blob/main/docs/adr/0015-reply-options.md)). How to use them in a bot: [Reply options](reply-options.md).
|
|
84
|
+
|
|
85
|
+
- **Limits.** One to four items, each trimmed, on one line, 1 to 80 characters (UTF-16 code units), all different, with nothing the visitor can't see (control, format, private-use or unassigned characters; the zero-width joiner in emoji is fine), and without links: no scheme such as `https://` or `mailto:`, no `www.`, no IP address and no domain name such as `example.com`. The server drops items that break these rules and sends no event when none is left; clients refuse an event that breaks them.
|
|
86
|
+
- **Plain text.** Show each item as text, never as Markdown or HTML.
|
|
87
|
+
- **Only under the latest answer.** Hide the options as soon as the visitor sends anything.
|
|
88
|
+
- **A click is a message.** Send the item's text through `POST /messages` like typed text. The server can't tell the difference, and nothing else travels with it.
|
|
89
|
+
|
|
90
|
+
Older clients ignore the event, so it is additive in protocol version 1.
|
|
91
|
+
|
|
80
92
|
## Identity
|
|
81
93
|
|
|
82
94
|
`POST /session` takes an optional `identityToken`: the JWT from `askdare('identify')`, or `null` to sign out. Without it, a renewal keeps the identity the previous access token had. Widgets send the page's latest token with every session request. The answer adds `identified` (boolean), `identityKey` (an HMAC that tells users apart without revealing them; widgets keep one conversation handle per key), `resumeToken` when signing in adopted an anonymous conversation, and `identityProblem` when a token was refused. A signed-in access token expires with the identity token. Identities travel inside the encrypted access token; clients never see the claims ([ADR-0009](https://github.com/boldare/askdare/blob/main/docs/adr/0009-visitor-identity.md)).
|
package/docs/react.md
CHANGED
|
@@ -132,6 +132,7 @@ function Bubble() {
|
|
|
132
132
|
<Chat.Citations />
|
|
133
133
|
<Chat.FeedbackButton rating="up">👍</Chat.FeedbackButton>
|
|
134
134
|
<Chat.FeedbackButton rating="down">👎</Chat.FeedbackButton>
|
|
135
|
+
<Chat.QuickReplies />
|
|
135
136
|
</Chat.Message>
|
|
136
137
|
);
|
|
137
138
|
}
|
|
@@ -175,6 +176,7 @@ Without `Theme` and `DefaultChat`, no stylesheet of the chat loads: the look is
|
|
|
175
176
|
| `Citations` | `ol` | The answer's sources. |
|
|
176
177
|
| `MessageFiles` | `ul` or `p` | The files sent with a message. |
|
|
177
178
|
| `FeedbackButton` | `button` | Rates the answer; takes `rating="up"` or `"down"`. See [Answer ratings](feedback.md). |
|
|
179
|
+
| `QuickReplies` | `div` | The options the latest answer offers, as a group of buttons (`reply`) that show their text as plain text. A click sends the option as the visitor's message. Inside `MessageList` it renders under the latest answer only; placed anywhere else, such as above the `Composer`, it shows the latest answer's options there. Either way they go away once the visitor sends anything. The default look follows the theme's `replies` variant ([Themes](themes.md#variants)). See [Reply options](reply-options.md#in-react). |
|
|
178
180
|
| `Composer` | `form` | Submitting it sends the draft, Enter in the `Input` included. An `onSubmit` of yours that calls `event.preventDefault()` takes the message over. |
|
|
179
181
|
| `Input` | `textarea` | The message field: Enter sends, Shift+Enter starts a new line, pasted files are attached. Your `onKeyDown` or `onPaste` can prevent either. |
|
|
180
182
|
| `Send` | `button` | Sends; disabled until there is something to send. |
|
|
@@ -199,7 +201,7 @@ Primitives that have nothing to show render nothing, so you can place them witho
|
|
|
199
201
|
| --- | --- |
|
|
200
202
|
| `phase` | `'starting'` on the server and until the chat knows the visitor, `'loading'` while a stored conversation loads, then `'ready'`. |
|
|
201
203
|
| `busy` | A turn is under way. |
|
|
202
|
-
| `messages` | Each with `id`, `role`, `text`, `status` (`'streaming'`, `'done'`, `'error'`), `citations`, `files` and `
|
|
204
|
+
| `messages` | Each with `id`, `role`, `text`, `status` (`'streaming'`, `'done'`, `'error'`), `citations`, `files`, `feedback` and `replies` (the options the answer offers, plain text). |
|
|
203
205
|
| `draft`, `files` | The message field's text and the files picked for the next message. |
|
|
204
206
|
| `error`, `activity` | The latest problem, and what the assistant is doing before it writes. |
|
|
205
207
|
| `dictation`, `elapsed`, `canDictate` | The dictation: `'idle'`, `'recording'` or `'transcribing'`, its seconds, and whether this browser can record. |
|
|
@@ -207,7 +209,7 @@ Primitives that have nothing to show render nothing, so you can place them witho
|
|
|
207
209
|
|
|
208
210
|
| `actions` | Meaning |
|
|
209
211
|
| --- | --- |
|
|
210
|
-
| `send(text?)` | Sends the draft, or `text` on its own (a suggested question). |
|
|
212
|
+
| `send(text?)` | Sends the draft, or `text` on its own (a suggested question, or one of the latest answer's `replies`). |
|
|
211
213
|
| `setDraft(text)` | Sets the message field. |
|
|
212
214
|
| `addFiles(files)`, `removeFile(key)` | Files for the next message. |
|
|
213
215
|
| `startDictation()`, `finishDictation()`, `cancelDictation()` | Dictation; finishing puts the transcript into the draft. |
|
|
@@ -281,4 +283,5 @@ The copy imports only `@boldare/askdare/react`, so `Root`, the hooks and the pri
|
|
|
281
283
|
- **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.
|
|
282
284
|
- **Several chats on a page** work, each in its own `Root`, also for different bots with different themes.
|
|
283
285
|
- **One conversation per bot and browser**, shared by every page that shows that bot, and by the widget on the same origin.
|
|
286
|
+
- **Switching the language.** Call `getChatConfig` with the new `locale` and pass the result to `Root`: it starts the chat again in that language, and the conversation stays. The texts, starters and greeting change with it. An answer still streaming disappears from view, `onEvent` gets `message.received` with `outcome: 'stopped'`, and the server still finishes and stores it. Only a bot with `locale: 'auto'` switches; see [Texts](texts.md#switching-the-language-on-the-page).
|
|
284
287
|
- **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`.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Reply options
|
|
2
|
+
|
|
3
|
+
Reply options are a few buttons under the bot's latest answer, such as "Track the parcel" or "Talk to a person". The visitor clicks one instead of typing. They help most when the next step is obvious but tedious to type: answering a question the bot just asked, picking from a short list, or asking the usual follow-up ([ADR-0015](https://github.com/boldare/askdare/blob/main/docs/adr/0015-reply-options.md)).
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
Bot: Your order 104233 shipped yesterday with DHL.
|
|
7
|
+
It should arrive on Thursday.
|
|
8
|
+
|
|
9
|
+
[ Track the parcel ] [ Talk to a person ]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
- **Only the latest answer has options.** They disappear as soon as the visitor sends anything, typed or clicked.
|
|
13
|
+
- **A click sends the option's text as the visitor's message,** exactly as if they had typed it. Their message in the chat is that text.
|
|
14
|
+
- **They come back after a reload,** as long as the visitor hasn't written since.
|
|
15
|
+
|
|
16
|
+
## Pick a source
|
|
17
|
+
|
|
18
|
+
Options come from the model or from your tools. A bot can use both.
|
|
19
|
+
|
|
20
|
+
| | The model suggests them | A tool defines them |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| Turn on | `widget.replies: 'suggest'` on the bot | `replies` in `defineTool` |
|
|
23
|
+
| Who writes them | The model, from the conversation | Your code, from the tool's result |
|
|
24
|
+
| Good for | Follow-up questions, answers to a question the bot asked, any topic | Fixed next steps of a known flow: an order, a booking, a plan |
|
|
25
|
+
| Same every time | No: the model decides whether and what to suggest | Yes: the same result gives the same options |
|
|
26
|
+
| Language | The answer's | Whatever your code returns ([see below](#options-in-the-visitors-language)) |
|
|
27
|
+
| Cost | More input tokens, and sometimes one more model call ([Cost](#cost)) | None: your code runs on the server after the tool |
|
|
28
|
+
|
|
29
|
+
**Tool options win.** When a tool defines options during an answer, the model isn't offered `suggest_replies` again in that answer, and a suggestion it made earlier in the same answer is dropped. When several tool calls define options, the last call's win.
|
|
30
|
+
|
|
31
|
+
## Let the model suggest them
|
|
32
|
+
|
|
33
|
+
Turn it on per bot:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// askdare.config.ts
|
|
37
|
+
defineBot({
|
|
38
|
+
id: 'support',
|
|
39
|
+
// …
|
|
40
|
+
widget: {
|
|
41
|
+
replies: 'suggest',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The model gets a built-in tool, `suggest_replies`, whose description tells it to offer 2 to 4 short replies when a few clear next steps would help, and to skip them for greetings and small talk. The server answers the call itself; none of your code runs, and the visitor sees no tool status.
|
|
47
|
+
|
|
48
|
+
Models often leave the options out, even after asking the visitor to choose. Say when you want them in your instructions:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
defineBot({
|
|
52
|
+
id: 'support',
|
|
53
|
+
instructions: ({ locale }) =>
|
|
54
|
+
`You answer questions about Brightloop's plans and support. Reply in ${locale}. ` +
|
|
55
|
+
'After an answer about Brightloop, suggest replies: the likely answers when you asked ' +
|
|
56
|
+
'the visitor something, otherwise the follow-up questions they would most likely ask next.',
|
|
57
|
+
widget: { replies: 'suggest' },
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
After "Which plan are you on?", the visitor might see `Free`, `Team`, `Enterprise`; after an answer about pricing, `Is there a yearly discount?`, `How do I upgrade?`.
|
|
62
|
+
|
|
63
|
+
The model can't suggest options on the last model call of a message, because that call must answer in words. A bot with `limits.maxSteps: 1` therefore never shows suggested options.
|
|
64
|
+
|
|
65
|
+
## Define them in a tool
|
|
66
|
+
|
|
67
|
+
Give `defineTool` a `replies` function. It receives the tool's result and returns the options, or `undefined` for none ([Tools](tools.md#reply-options)).
|
|
68
|
+
|
|
69
|
+
### Example: an order-status flow
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
// tools.ts
|
|
73
|
+
import { defineTool } from '@boldare/askdare';
|
|
74
|
+
import { z } from 'zod';
|
|
75
|
+
|
|
76
|
+
export const orderStatus = defineTool({
|
|
77
|
+
name: 'get_order_status',
|
|
78
|
+
description: 'Status of an order by its number. Use it when the visitor asks about an order.',
|
|
79
|
+
input: z.object({
|
|
80
|
+
orderNumber: z.string().regex(/^\d{6}$/).describe('Six-digit order number'),
|
|
81
|
+
}),
|
|
82
|
+
execute: async ({ orderNumber }, { signal }) => {
|
|
83
|
+
const response = await fetch(`https://shop.example.com/api/orders/${orderNumber}`, { signal });
|
|
84
|
+
if (!response.ok) return { error: 'No such order.' };
|
|
85
|
+
const order = (await response.json()) as { status: 'processing' | 'shipped' | 'delivered' };
|
|
86
|
+
return { orderNumber, status: order.status };
|
|
87
|
+
},
|
|
88
|
+
replies: (order) => {
|
|
89
|
+
if ('error' in order) return ['Try another order number', 'Talk to a person'];
|
|
90
|
+
switch (order.status) {
|
|
91
|
+
case 'processing':
|
|
92
|
+
return ['Change the delivery address', 'Cancel the order', 'Talk to a person'];
|
|
93
|
+
case 'shipped':
|
|
94
|
+
return ['Track the parcel', 'Talk to a person'];
|
|
95
|
+
case 'delivered':
|
|
96
|
+
return ['Return an item', 'Something is missing'];
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The visitor asks "Where is my order 104233?", the model calls the tool and writes the answer, and the options under it match the order's state. A click on "Track the parcel" sends that text; the model reads it and answers, for example by calling a tracking tool. Each option must be something your bot can actually handle: instructions, a knowledge base or another tool that covers it.
|
|
103
|
+
|
|
104
|
+
### Example: picking a time slot
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
export const freeSlots = defineTool({
|
|
108
|
+
name: 'find_free_slots',
|
|
109
|
+
description: 'Free consultation slots in the next 7 days. Use it before suggesting a time.',
|
|
110
|
+
input: z.object({ topic: z.enum(['sales', 'support']) }),
|
|
111
|
+
execute: async ({ topic }, { signal }) => {
|
|
112
|
+
const slots = await calendar.freeSlots(topic, { days: 7, signal }); // your calendar's API
|
|
113
|
+
return { topic, slots: slots.slice(0, 3).map((slot) => slot.label) }; // "Tue 14 Nov, 10:00"
|
|
114
|
+
},
|
|
115
|
+
replies: ({ slots }) => (slots.length > 0 ? [...slots, 'None of these work'] : undefined),
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Three slots and a way out fit the limit of four. The visitor clicks "Tue 14 Nov, 10:00", and the model gets that as their message.
|
|
120
|
+
|
|
121
|
+
**An option is not a confirmation.** "Yes, book it" arrives as a message the visitor could also have typed, and the model, not your code, decides what happens next. Tools are [read-only for now](tools.md#rules): don't build a write action on the assumption that a click confirmed it.
|
|
122
|
+
|
|
123
|
+
### Options in the visitor's language
|
|
124
|
+
|
|
125
|
+
`replies` gets only the result. If your bot speaks several languages, put the visitor's language into the result in `execute` and pick the labels from it:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const LABELS = {
|
|
129
|
+
en: { track: 'Track the parcel', human: 'Talk to a person' },
|
|
130
|
+
pl: { track: 'Śledź paczkę', human: 'Porozmawiaj z człowiekiem' },
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const orderStatus = defineTool({
|
|
134
|
+
// … name, description and input as above
|
|
135
|
+
execute: async ({ orderNumber }, { locale, signal }) => {
|
|
136
|
+
// … fetch the order
|
|
137
|
+
return { orderNumber, status: order.status, lang: locale.startsWith('pl') ? 'pl' : 'en' };
|
|
138
|
+
},
|
|
139
|
+
replies: ({ lang, status }) => {
|
|
140
|
+
const t = LABELS[lang];
|
|
141
|
+
return status === 'shipped' ? [t.track, t.human] : [t.human];
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Options are stored with the conversation as the result was, so they come back in the language they were shown in. Suggested options follow the answer's language on their own.
|
|
147
|
+
|
|
148
|
+
## Limits and safety
|
|
149
|
+
|
|
150
|
+
The server cleans every option, from the model and from tools alike, and the chat checks them again:
|
|
151
|
+
|
|
152
|
+
- **At most 4 options, each at most 80 characters,** trimmed and on one line. Extra, empty and repeated ones are dropped.
|
|
153
|
+
- **Only what the visitor can read.** An option with invisible characters (zero-width or tag characters, direction marks, private-use code points) is dropped, because a click sends exactly that text as the visitor's message.
|
|
154
|
+
- **No links.** An option with a URL, `www.`, an IP address or anything that looks like a domain (`example.com`) is dropped. Put links in the answer, where the chat renders them safely.
|
|
155
|
+
- **Plain text.** Options are never rendered as Markdown or HTML, so `**bold**` shows as typed.
|
|
156
|
+
- **If nothing is left, no options show.** If your `replies` function throws, the answer comes without options and the error is logged.
|
|
157
|
+
|
|
158
|
+
**A click is only a message.** It doesn't run a tool, choose a flow or carry an ID: the server can't tell it from typed text, and it goes through the same limits and budgets ([ADR-0004](https://github.com/boldare/askdare/blob/main/docs/adr/0004-threat-model.md)). So write options the way the visitor would say them ("Cancel the order"), not as commands ("cancel_order"). An option the model was tricked into suggesting, for example by a document in the knowledge base, is at worst text the visitor chooses to send, which they could also have typed.
|
|
159
|
+
|
|
160
|
+
## Placement and styling
|
|
161
|
+
|
|
162
|
+
The theme's `replies` variant puts the options under the answer (`answer`, the default) or in one row above the message field that scrolls sideways (`composer`):
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { defineTheme } from '@boldare/askdare';
|
|
166
|
+
|
|
167
|
+
const brand = defineTheme({ extends: 'aura', variants: { replies: 'composer' } });
|
|
168
|
+
|
|
169
|
+
defineBot({ /* … */ widget: { theme: brand, replies: 'suggest' } });
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Style them with the parts `replies` (the group) and `reply` (each button). The group has `data-placement="composer"` above the message field ([Styling](styling.md#2-your-own-css)):
|
|
173
|
+
|
|
174
|
+
```css
|
|
175
|
+
[data-ask-part="reply"] {
|
|
176
|
+
border-radius: 999px;
|
|
177
|
+
font-weight: 600;
|
|
178
|
+
}
|
|
179
|
+
[data-ask-part="replies"][data-placement="composer"] {
|
|
180
|
+
padding-block: 4px;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The group's accessible name is the text `message.replies` ("Suggested replies"), which you can change like any [text](texts.md).
|
|
185
|
+
|
|
186
|
+
## In React
|
|
187
|
+
|
|
188
|
+
`DefaultChat` shows options as the widget does. With your own markup, render `QuickReplies` ([React](react.md#your-own-markup)). Inside a message it shows the options under the latest answer only; outside `MessageList` it shows the latest answer's options wherever you put it:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
'use client';
|
|
192
|
+
import * as Chat from '@boldare/askdare/react';
|
|
193
|
+
|
|
194
|
+
export function SupportChat({ config }: { config: Chat.ChatConfig }) {
|
|
195
|
+
return (
|
|
196
|
+
<Chat.Root config={config}>
|
|
197
|
+
<Chat.Panel className="support-chat">
|
|
198
|
+
<Chat.Messages>
|
|
199
|
+
<Chat.MessageList>
|
|
200
|
+
<Chat.Message>
|
|
201
|
+
<Chat.MessageText />
|
|
202
|
+
</Chat.Message>
|
|
203
|
+
</Chat.MessageList>
|
|
204
|
+
</Chat.Messages>
|
|
205
|
+
<Chat.QuickReplies className="support-replies" />
|
|
206
|
+
<Chat.Composer>
|
|
207
|
+
<Chat.Input />
|
|
208
|
+
<Chat.Send>Send</Chat.Send>
|
|
209
|
+
</Chat.Composer>
|
|
210
|
+
</Chat.Panel>
|
|
211
|
+
</Chat.Root>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The buttons are disabled while an answer streams. To build the buttons yourself, read `replies` of the latest message in `state.messages` from `useChat()`, and send one with `actions.send(text)`.
|
|
217
|
+
|
|
218
|
+
## Measure clicks
|
|
219
|
+
|
|
220
|
+
A clicked option fires `message.sent` with `source: 'reply'` ([Chat events](events.md)). The event says that an option was clicked, not which one: events never carry text.
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
askdare('on', 'message.sent', function (event) {
|
|
224
|
+
gtag('event', 'chat_message_sent', { chat_bot: event.bot, chat_source: event.source });
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Compare the share of `reply` with `typed` to see whether visitors use the options. askdare doesn't report which option was picked: neither events nor the server hooks carry message text ([Observability](observability.md#what-the-reports-contain)). For tool-defined options, the tools a click leads to tell you a lot: count them by `name` in the `tools` of [`onUsage`](configuration.md#onusage), such as the tracking tool after "Track the parcel".
|
|
229
|
+
|
|
230
|
+
## Cost
|
|
231
|
+
|
|
232
|
+
- **Tool-defined options cost nothing extra.** Your function runs on the server after the tool, and the model never sees the options.
|
|
233
|
+
- **Suggested options cost tokens.** The definition of `suggest_replies` (about 250 tokens) is input on every model call, mostly cached. When the model suggests options before it answers, the message takes one more model call. [Costs](costs.md#reply-options) explains both and how to measure them with `onUsage`.
|
|
234
|
+
|
|
235
|
+
## Troubleshooting
|
|
236
|
+
|
|
237
|
+
- **No options with `replies: 'suggest'`.** The model decided none would help. Say when you want them in the instructions, as [above](#let-the-model-suggest-them). Check that `limits.maxSteps` is above 1 and that the daily budgets aren't nearly used up: when the extra call doesn't fit, the model answers without options.
|
|
238
|
+
- **A tool's options don't show.** The call failed, timed out or returned too much data, `replies` returned `undefined` or threw (see the server log), or every option broke a limit: too long, repeated, or with a link.
|
|
239
|
+
- **The model lists the options in its answer as well.** askdare already tells it not to; if it still does, say in the instructions that the visitor sees the options as buttons.
|
|
240
|
+
- **Options from an earlier answer are gone.** That's by design: only the latest answer has them.
|
package/docs/styling.md
CHANGED
|
@@ -66,7 +66,7 @@ A full example is the demo site's BLDR theme, in Boldare's style: `defineTheme`
|
|
|
66
66
|
|
|
67
67
|
The launcher's short variables on your page (`--a`, `--o` and the like) are internal too.
|
|
68
68
|
|
|
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`.
|
|
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`, the options under the latest answer: `replies`, `reply`, 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`.
|
|
70
70
|
|
|
71
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.
|
|
72
72
|
|
|
@@ -82,6 +82,7 @@ The launcher's short variables on your page (`--a`, `--o` and the like) are inte
|
|
|
82
82
|
| `attachment` | `data-kind` | `image`, `pdf`; absent until the chat has recognized the file |
|
|
83
83
|
| `recorder` | `data-state` | `recording`, `transcribing` |
|
|
84
84
|
| `feedback-button` | `data-rating` | `up`, `down`; `aria-pressed="true"` on the visitor's rating |
|
|
85
|
+
| `replies` | `data-placement` | `composer` on the row above the message field (variant `replies: 'composer'`); absent under an answer |
|
|
85
86
|
| `avatar` | `data-kind` | `orb`, `icon`, `initials`, `image` |
|
|
86
87
|
| `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 |
|
|
87
88
|
| `welcome` | `data-layout` | `hero`, `persona`, `intro` |
|
|
@@ -150,10 +151,10 @@ Every preset sets both font tokens, so set both. You can also set them as the `f
|
|
|
150
151
|
| --- | --- |
|
|
151
152
|
| `askdare('open')`, `askdare('close')`, `askdare('toggle')` | Shows or hides the chat. Closing returns focus to whatever opened it. |
|
|
152
153
|
| `askdare('identify', token)` | Signs the visitor in with a token from your backend, or out with `null`; see [Signed-in visitors](identity.md). |
|
|
153
|
-
| `askdare('configure', { greeting, starters, context })` | Per-page greeting and suggestions,
|
|
154
|
+
| `askdare('configure', { greeting, starters, context, locale })` | Per-page greeting and suggestions, `context`: a short description of the page (up to 1000 characters) for the assistant, and `locale`: the chat's language, for a bot with `locale: 'auto'`. |
|
|
154
155
|
| `askdare('on', type, listener)`, `askdare('off', type, listener)` | Listens to what happens in the chat, such as a message sent or an answer rated, for analytics. Metadata only; see [Chat events](events.md). |
|
|
155
156
|
|
|
156
|
-
`configure` accepts only those
|
|
157
|
+
`configure` accepts only those four fields: never the model, instructions or tools. The context is off unless the bot opts in with `pageContext: true` in `defineBot`. It then travels with the visitor's message, as a marked part of their own turn: anyone can set it from their browser, so it gets no more trust than what the visitor types, and it never becomes part of the bot's instructions. It is sent again only when it changes, and the visitor's history doesn't show it. Define the small queue first, then call it any time:
|
|
157
158
|
|
|
158
159
|
```html
|
|
159
160
|
<script>
|
|
@@ -170,6 +171,8 @@ Every preset sets both font tokens, so set both. You can also set them as the `f
|
|
|
170
171
|
<script src="https://app.example.com/api/chat/widget.js?bot=support" async></script>
|
|
171
172
|
```
|
|
172
173
|
|
|
174
|
+
`locale` is a BCP 47 tag, such as `'pl'`, and the server checks it against the bot like any language. It reloads the chat in that language and keeps the conversation; a call with only `locale` leaves the greeting, suggestions and context as they were. To follow your page's `<html lang>` instead, add `data-follow-lang` to the script tag. See [Texts](texts.md#switching-the-language-on-the-page).
|
|
175
|
+
|
|
173
176
|
An inline chat loads with the page without taking focus or scrolling to itself.
|
|
174
177
|
|
|
175
178
|
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.
|