@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/dist/version.js
CHANGED
|
@@ -25,6 +25,12 @@ const EN = {
|
|
|
25
25
|
"status.tool": "Using {name}…",
|
|
26
26
|
"status.typing": "The assistant is typing",
|
|
27
27
|
"message.sources": "Sources",
|
|
28
|
+
"feedback.label": "Rate this answer",
|
|
29
|
+
"feedback.up": "Helpful",
|
|
30
|
+
"feedback.down": "Not helpful",
|
|
31
|
+
"feedback.comment": "What went wrong?",
|
|
32
|
+
"feedback.send": "Send feedback",
|
|
33
|
+
"feedback.skip": "Skip",
|
|
28
34
|
"message.attachments.one": "{count} attachment",
|
|
29
35
|
"message.attachments.other": "{count} attachments",
|
|
30
36
|
"attachment.list": "Attachments",
|
|
@@ -112,6 +118,12 @@ const PL = {
|
|
|
112
118
|
"status.tool": "Korzystam z narzędzia {name}…",
|
|
113
119
|
"status.typing": "Asystent pisze",
|
|
114
120
|
"message.sources": "Źródła",
|
|
121
|
+
"feedback.label": "Oceń tę odpowiedź",
|
|
122
|
+
"feedback.up": "Pomocna",
|
|
123
|
+
"feedback.down": "Niepomocna",
|
|
124
|
+
"feedback.comment": "Co było nie tak?",
|
|
125
|
+
"feedback.send": "Wyślij opinię",
|
|
126
|
+
"feedback.skip": "Pomiń",
|
|
115
127
|
"message.attachments.one": "{count} załącznik",
|
|
116
128
|
"message.attachments.few": "{count} załączniki",
|
|
117
129
|
"message.attachments.many": "{count} załączników",
|
package/docs/cli.md
CHANGED
|
@@ -11,6 +11,7 @@ npx @boldare/askdare <command> [options]
|
|
|
11
11
|
| [`init`](#init) | Adds askdare to the app: a bot config, the route, `.env.local` and the chat script. |
|
|
12
12
|
| [`doctor`](#doctor) | Checks the project, its environment and the running app. |
|
|
13
13
|
| [`kb sync <folder>`](#kb-sync) | Makes an OpenAI vector store mirror a folder of documents. |
|
|
14
|
+
| [`add ui`](#add-ui) | Copies the chat's default look into the app as your own React components. |
|
|
14
15
|
| [`-v`, `--version`](#version-and-help) | Prints the installed version. |
|
|
15
16
|
| [`-h`, `--help`](#version-and-help) | Prints the usage. |
|
|
16
17
|
|
|
@@ -205,6 +206,34 @@ Synced: 2 added, 0 retagged, 1 removed, 12 unchanged.
|
|
|
205
206
|
|
|
206
207
|
A file that fails to upload is listed as `Failed: <path> (<reason>)`, and the rest of the sync goes on.
|
|
207
208
|
|
|
209
|
+
## add ui
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
npx @boldare/askdare add ui
|
|
213
|
+
npx @boldare/askdare add ui --dir app/_chat
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Copies the source of the chat's default look into your app, for the chat inside a page ([React](react.md)). Use it when configuration, CSS and the slots of `DefaultChat` aren't enough and you want to change the components themselves. The files are yours from then on: later versions of askdare don't touch them, so take changes to the look from the changelog by hand.
|
|
217
|
+
|
|
218
|
+
| Option | Default | Meaning |
|
|
219
|
+
| --- | --- | --- |
|
|
220
|
+
| `--dir <folder>` | `components/askdare`, or `src/components/askdare` when the app keeps its code in `src/` | Where to put the files, inside the app. |
|
|
221
|
+
|
|
222
|
+
### What it writes
|
|
223
|
+
|
|
224
|
+
About a dozen files in one folder: the components (`chat.tsx` with `DefaultChat`, `panel.tsx`, `header.tsx`, `welcome.tsx`, `message.tsx`, `feedback.tsx`, `footer.tsx`, `confirm.tsx`, `avatar.tsx`, `icons.tsx`, `context.ts`), their stylesheet `askdare.css`, and `index.ts`. Each starts with the version it was copied from.
|
|
225
|
+
|
|
226
|
+
- The components import only `@boldare/askdare/react` and each other. Streaming, limits and security stay in the library.
|
|
227
|
+
- `chat.tsx` imports `askdare.css`, so your bundler ships the stylesheet. The theme's tokens and fonts still come from the chat route.
|
|
228
|
+
- **It never overwrites.** If one of the files is already in the folder, nothing is written and the command exits with `1`.
|
|
229
|
+
|
|
230
|
+
Then change one import where you render the chat:
|
|
231
|
+
|
|
232
|
+
```diff
|
|
233
|
+
- import { DefaultChat } from '@boldare/askdare/react';
|
|
234
|
+
+ import { DefaultChat } from '@/components/askdare';
|
|
235
|
+
```
|
|
236
|
+
|
|
208
237
|
## Version and help
|
|
209
238
|
|
|
210
239
|
```bash
|
|
@@ -222,6 +251,7 @@ npx @boldare/askdare --help
|
|
|
222
251
|
| `init` | Done. | The folder isn't a Next.js app with the App Router, or the bot ID is invalid. |
|
|
223
252
|
| `doctor` | No problems. Warnings don't count. | At least one `✗` problem. |
|
|
224
253
|
| `kb sync` | Done, or nothing to do. | At least one file failed to upload. |
|
|
254
|
+
| `add ui` | Done. | The folder isn't a Next.js app with React, `--dir` is outside it, or a file is already there. |
|
|
225
255
|
| All | | An unknown command or option, or a missing or invalid value, such as a `--url` without `https` or no `OPENAI_API_KEY` for `kb sync`. The usage is printed with the error. Any other error is printed as `askdare: <message>`. |
|
|
226
256
|
|
|
227
257
|
`doctor` exits with `1` while there is a problem, so you can run it in CI after a deploy.
|
package/docs/configuration.md
CHANGED
|
@@ -5,7 +5,8 @@ You configure askdare in two places:
|
|
|
5
5
|
| Where | What | Import |
|
|
6
6
|
| --- | --- | --- |
|
|
7
7
|
| `askdare.config.ts` | One `defineBot({ … })` per bot: its model, instructions, features, limits and look. | `@boldare/askdare` |
|
|
8
|
-
| `app/api/chat/[...path]/route.ts` | One `createChatHandler({ … })` for all bots: secrets, the counter store, the client IP and
|
|
8
|
+
| `app/api/chat/[...path]/route.ts` | One `createChatHandler({ … })` for all bots: secrets, the counter store, the client IP, error reporting, usage reports (`onUsage`) and ratings (`onFeedback`). | `@boldare/askdare/next` |
|
|
9
|
+
| A page of your app (Server Component) | `getChatConfig({ bots, bot })` for the chat inside a page: see [React](react.md). | `@boldare/askdare/next` |
|
|
9
10
|
|
|
10
11
|
`defineBot` checks the whole definition when your app starts. It throws a `TypeError` that lists every problem, for example:
|
|
11
12
|
|
|
@@ -206,6 +207,7 @@ Everything in `widget` is sent to browsers. Never put secrets in it. [Styling](s
|
|
|
206
207
|
| `texts` | `Partial<Record<TextKey, string>>` | `{}` | Any widget text by its key, 1–300 characters each. |
|
|
207
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. |
|
|
208
209
|
| `starters` | `string[]` | `[]` | Suggested questions on the welcome screen. Up to 4, 1–80 characters each. |
|
|
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. |
|
|
209
211
|
| `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. |
|
|
210
212
|
| `theme` | `PresetName \| ThemeDefinition` | `'aura'` | `'halo'`, `'aura'`, `'sage'`, `'care'`, or a theme from `defineTheme`. |
|
|
211
213
|
| `colorScheme` | `'auto' \| 'light' \| 'dark'` | `'auto'` | `'auto'` follows the visitor's system setting. |
|
|
@@ -215,7 +217,7 @@ The text defaults come from the built-in dictionary of the configured language.
|
|
|
215
217
|
|
|
216
218
|
## `createChatHandler`
|
|
217
219
|
|
|
218
|
-
`createChatHandler(options: ChatHandlerOptions): ChatHandlers` returns `GET`, `POST` and `DELETE` for the catch-all route. Its types are exported from `@boldare/askdare/next`: `ChatHandlerOptions`, `ChatHandlerLimitsOptions`, `ChatErrorReport`, `TrustProxy`, `ChatHandlers` and `RouteHandler`.
|
|
220
|
+
`createChatHandler(options: ChatHandlerOptions): ChatHandlers` returns `GET`, `POST` and `DELETE` for the catch-all route. Its types are exported from `@boldare/askdare/next`: `ChatHandlerOptions`, `ChatHandlerLimitsOptions`, `ChatErrorReport`, `ChatUsageReport`, `ChatTokenUsage`, `ChatToolCallReport`, `ChatFeedbackReport`, `TrustProxy`, `ChatHandlers` and `RouteHandler`.
|
|
219
221
|
|
|
220
222
|
| Option | Type | Default | Notes |
|
|
221
223
|
| --- | --- | --- | --- |
|
|
@@ -226,7 +228,9 @@ The text defaults come from the built-in dictionary of the configured language.
|
|
|
226
228
|
| `previousSecrets` | `readonly string[]` | `process.env.CHAT_SECRET_PREVIOUS`, split at commas | Former secrets that still verify tokens during a rotation. Each follows the same rule as `secret`. See [Going public](going-public.md#2-secrets-and-environment). |
|
|
227
229
|
| `identitySecret` | `string` | `process.env.IDENTITY_SECRET` | Checks identity tokens from your site's backend. Same rule as `secret`, and it must differ from it. Without one, identity is off. See [Signed-in visitors](identity.md). |
|
|
228
230
|
| `limits` | `ChatHandlerLimitsOptions` | see [Handler limits](#handler-limits) | The counter store, the client IP and a budget across bots. |
|
|
229
|
-
| `onError` | `(report: ChatErrorReport) => void
|
|
231
|
+
| `onError` | `(report: ChatErrorReport) => void \| Promise<void>` | one `console.error` line | Your error reporting. See [`onError`](#onerror). |
|
|
232
|
+
| `onUsage` | `(report: ChatUsageReport) => void \| Promise<void>` | none | Each turn's tokens, timings and tool calls, for cost tracking and tracing. See [`onUsage`](#onusage). |
|
|
233
|
+
| `onFeedback` | `(report: ChatFeedbackReport) => void \| Promise<void>` | none | Visitors' ratings of answers. Without it, answers can't be rated. See [`onFeedback`](#onfeedback). |
|
|
230
234
|
| `gallery` | `boolean` | `false` | Serves the state gallery. See [`gallery`](#gallery). |
|
|
231
235
|
|
|
232
236
|
A wrong `basePath`, a duplicate bot ID or an empty `bots` list throws a `TypeError` when the route loads. A missing key or a missing or weak secret doesn't stop the route from loading. Instead, requests that need it answer `bot_unavailable`, and `onError` receives the reason. In development (`next dev`), the chat itself says what to fix.
|
|
@@ -258,7 +262,7 @@ See [Deployment](deployment.md#behind-another-proxy-or-cdn) for setups with a CD
|
|
|
258
262
|
|
|
259
263
|
### `onError`
|
|
260
264
|
|
|
261
|
-
`onError` receives server errors (status 500 and up), any error that ends an answer while it streams, and once a day a `budget_exceeded` report when a bot's or the global budget runs out (never a single visitor's). Use it for your monitoring. It never receives message contents or API keys.
|
|
265
|
+
`onError` receives server errors (status 500 and up), any error that ends an answer while it streams, and once a day a `budget_exceeded` report when a bot's or the global budget runs out (never a single visitor's). Use it for your monitoring. It never receives message contents or API keys. It may be async: askdare keeps the function alive until it finishes, and anything it throws is logged by its error's name and never reaches the request.
|
|
262
266
|
|
|
263
267
|
```ts
|
|
264
268
|
import * as Sentry from '@sentry/nextjs';
|
|
@@ -283,6 +287,69 @@ Without `onError`, askdare logs one `console.error` line with the code, what wen
|
|
|
283
287
|
|
|
284
288
|
`code` is one of `invalid_input`, `unauthorized`, `session_expired`, `not_found`, `rate_limited`, `budget_exceeded`, `bot_unavailable`, `content_blocked` (reserved, not sent yet), `timeout`, `upstream_error` or `internal_error`. The codes at status 500 and up are `internal_error` (500), `upstream_error` (502), `bot_unavailable` (503) and `timeout` (504). [Protocol](protocol.md#error-codes) explains each one.
|
|
285
289
|
|
|
290
|
+
### `onUsage`
|
|
291
|
+
|
|
292
|
+
`onUsage` is called once per chat turn, after the answer has streamed, including turns that failed. It receives the tokens the turn used, how long it took and which tools it called, for cost tracking, dashboards and tracing (ADR-0012). It holds counters and pseudonyms only: never message text, tool arguments or results, IP addresses or raw IDs.
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
296
|
+
bots,
|
|
297
|
+
onUsage: async ({ bot, model, usage, durationMs }) => {
|
|
298
|
+
await metrics.record('chat.turn', { bot, model, ...usage, durationMs });
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
It may be async. askdare calls it after the stream has closed, so it never delays an answer, keeps the function alive until it finishes, and logs anything it throws by its error's name. For OpenTelemetry spans, pass `otelUsage()` from `@boldare/askdare-otel`; see [Observability](observability.md).
|
|
304
|
+
|
|
305
|
+
`ChatUsageReport`:
|
|
306
|
+
|
|
307
|
+
| Field | Type | Meaning |
|
|
308
|
+
| --- | --- | --- |
|
|
309
|
+
| `bot` | `string` | The bot's ID. |
|
|
310
|
+
| `model` | `string` | The model that answered, as OpenAI reports it. The configured model if none answered. |
|
|
311
|
+
| `conversation` | `string \| undefined` | A pseudonym (HMAC) of the conversation, the same for every turn of it. Undefined when none was created. |
|
|
312
|
+
| `visitor` | `string` | A pseudonym (HMAC) of the signed-in user's ID, or of the visitor's when nobody is signed in: the same value OpenAI gets as `safety_identifier`. |
|
|
313
|
+
| `startedAt` | `number` | When the turn started, in epoch milliseconds. |
|
|
314
|
+
| `durationMs` | `number` | From the request to the end of the answer. |
|
|
315
|
+
| `outcome` | `'completed' \| 'stopped' \| 'failed'` | `stopped` when the turn was aborted before it could answer. |
|
|
316
|
+
| `finishReason` | `string` | Why the answer ended: `completed`, `max_steps`, `max_output_tokens` or `content_filter`. Absent when it failed. |
|
|
317
|
+
| `errorCode` | `string` | The stable error code (see [`onError`](#onerror)), when it failed. |
|
|
318
|
+
| `usage` | `ChatTokenUsage` | `inputTokens`, `cachedInputTokens`, `cacheWriteTokens`, `outputTokens` and `reasoningTokens`, summed over the turn's model calls. Cached and cache-write tokens are part of the input; reasoning tokens are part of the output. |
|
|
319
|
+
| `steps` | `number` | Model calls in the turn: one, plus one after each round of tool calls. |
|
|
320
|
+
| `tools` | `ChatToolCallReport[]` | One per function call: `name`, `startedAt`, `durationMs` and `outcome` (`ok`, `error` or `timeout`). |
|
|
321
|
+
|
|
322
|
+
The pseudonyms change when `CHAT_SECRET` rotates. A turn that fails mid-stream reports the usage askdare saw, which can be less than what OpenAI bills; [Costs](costs.md) explains the difference.
|
|
323
|
+
|
|
324
|
+
### `onFeedback`
|
|
325
|
+
|
|
326
|
+
With `onFeedback`, visitors can rate each answer 👍 or 👎, add a comment after 👎, and take a rating back. askdare stores no ratings: it hands each one to this function, after the response, so you can keep them where you keep other data.
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
330
|
+
bots,
|
|
331
|
+
onFeedback: async ({ bot, rating, comment, conversationId, itemId }) => {
|
|
332
|
+
await db.insert(ratings).values({ bot, rating, comment, conversationId, itemId });
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
It may be async, like `onUsage`, and nothing it throws reaches the chat. A bot hides the buttons with `widget.feedback: false`. What visitors see, and how a 👎 and its comment arrive, is in [Answer ratings](feedback.md).
|
|
338
|
+
|
|
339
|
+
`ChatFeedbackReport`:
|
|
340
|
+
|
|
341
|
+
| Field | Type | Meaning |
|
|
342
|
+
| --- | --- | --- |
|
|
343
|
+
| `bot` | `string` | The bot's ID. |
|
|
344
|
+
| `rating` | `'up' \| 'down' \| null` | `null` when the visitor took their rating back. |
|
|
345
|
+
| `comment` | `string` | What the visitor wrote, up to 500 characters. Absent when they wrote nothing or took the rating back. Treat it as personal data. |
|
|
346
|
+
| `visitor` | `string` | The same pseudonym `onUsage` reports, so ratings and costs line up. |
|
|
347
|
+
| `identity` | `VisitorIdentity` | The signed-in user, verified ([Signed-in visitors](identity.md)). Absent for anonymous visitors. |
|
|
348
|
+
| `conversationId` | `string` | The OpenAI conversation, for your own review of it, e.g. with `openai.conversations.items.list`. Never sent to the browser. |
|
|
349
|
+
| `itemId` | `string` | The OpenAI ID of the rated answer within that conversation. |
|
|
350
|
+
|
|
351
|
+
A visitor can rate only answers in their own conversations: each answer carries an encrypted handle bound to the visitor, or to the signed-in user, and the bot. Ratings are limited to 20 per minute per visitor.
|
|
352
|
+
|
|
286
353
|
### `gallery`
|
|
287
354
|
|
|
288
355
|
`gallery: true` serves the state gallery. `<basePath>/embed/<bot>?gallery=<state>&preset=<preset>&scheme=<scheme>` then renders a fixed state of the widget without calling the model.
|
|
@@ -355,3 +422,6 @@ A database from the Vercel Marketplace (Upstash for Redis) sets the `KV_` names
|
|
|
355
422
|
| Deploy to Vercel or Heroku | [Deployment](deployment.md) |
|
|
356
423
|
| Change texts, language or CSS | [Styling](styling.md) |
|
|
357
424
|
| Pick or adjust a theme | [Themes](themes.md) |
|
|
425
|
+
| Report costs or trace turns | [Observability](observability.md) |
|
|
426
|
+
| Collect ratings of answers | [Answer ratings](feedback.md) |
|
|
427
|
+
| Put the chat inside a page of your app | [React](react.md) |
|
package/docs/costs.md
CHANGED
|
@@ -128,6 +128,12 @@ export const { GET, POST, DELETE } = createChatHandler({
|
|
|
128
128
|
});
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
## Tracking what the chat costs
|
|
132
|
+
|
|
133
|
+
[`onUsage`](configuration.md#onusage) receives every turn's tokens as OpenAI reports them: input, cached and cache-write input, output and reasoning, with the model that answered. Multiply them by your model's prices to get the cost per turn, per bot or per conversation, and send them to your metrics or, with `@boldare/askdare-otel`, to your tracing.
|
|
134
|
+
|
|
135
|
+
The report holds pseudonyms, never message text. A turn that breaks off mid-answer reports what askdare received, while OpenAI may bill a little more, so compare with the OpenAI dashboard now and then.
|
|
136
|
+
|
|
131
137
|
## Choosing a model
|
|
132
138
|
|
|
133
139
|
The model decides most of the bill, which is why askdare never picks one for you.
|
|
@@ -149,7 +155,7 @@ A conversation is stored by OpenAI, and every message sends the whole conversati
|
|
|
149
155
|
|
|
150
156
|
- `maxTurns` (default 50) ends a conversation: the visitor is asked to start a new one.
|
|
151
157
|
- askdare sends `truncation: 'auto'`. When a conversation outgrows the model's context window, OpenAI drops the oldest items instead of failing.
|
|
152
|
-
- askdare doesn't compact or summarize conversations yet. OpenAI's server-side compaction is planned for 0.
|
|
158
|
+
- askdare doesn't compact or summarize conversations yet. OpenAI's server-side compaction is planned for 0.3: in [spike S5](https://github.com/boldare/askdare/blob/main/spikes/s5-compaction/README.md) it could cut answers off and under-report tokens, so it waits for a larger test.
|
|
153
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)).
|
|
154
160
|
|
|
155
161
|
## Prompt caching
|
package/docs/embedding.md
CHANGED
|
@@ -213,6 +213,8 @@ export default function RootLayout({ children }: { readonly children: ReactNode
|
|
|
213
213
|
|
|
214
214
|
An inline chat inside a React app has a hydration caveat. [Styling](styling.md#3-page-javascript) explains it.
|
|
215
215
|
|
|
216
|
+
In the Next.js app that serves the chat, you can also render it without an iframe, as React components in your own pages: see [The chat inside your page](react.md).
|
|
217
|
+
|
|
216
218
|
## Staging and production
|
|
217
219
|
|
|
218
220
|
Each environment usually embeds the chat on different sites. Read the list from an environment variable, for example `ASKDARE_ALLOWED_ORIGINS`, split on commas:
|
package/docs/feedback.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Answer ratings
|
|
2
|
+
|
|
3
|
+
Visitors can rate each answer with 👍 or 👎 and, after a 👎, say what went wrong. askdare stores no ratings: every one goes to your `onFeedback` function, and you decide where to keep it ([ADR-0012](https://github.com/boldare/askdare/blob/main/docs/adr/0012-server-hooks-and-telemetry.md)).
|
|
4
|
+
|
|
5
|
+
## Turn ratings on
|
|
6
|
+
|
|
7
|
+
Pass `onFeedback` to `createChatHandler`. Without it the buttons don't show, because there would be nowhere to send a rating.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// app/api/chat/[...path]/route.ts
|
|
11
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
12
|
+
bots,
|
|
13
|
+
onFeedback: async ({ bot, rating, comment, conversationId, itemId, visitor }) => {
|
|
14
|
+
await db.insert(ratings).values({ bot, rating, comment, conversationId, itemId, visitor });
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The function may be async. It runs after the response, and nothing it throws reaches the chat. The fields of the report are listed under [`onFeedback` in Configuration](configuration.md#onfeedback).
|
|
20
|
+
|
|
21
|
+
To hide the buttons for one bot, set `widget: { feedback: false }` in its `defineBot`.
|
|
22
|
+
|
|
23
|
+
## What visitors see
|
|
24
|
+
|
|
25
|
+
- **👍 and 👎** under every finished answer. The pressed button shows the visitor's rating, and a second click on it takes the rating back.
|
|
26
|
+
- **"What went wrong?"** after a 👎: a short field with **Send feedback** and **Skip**. The comment is optional and holds up to 500 characters. Escape skips it too.
|
|
27
|
+
- **Their rating again after a reload.** The browser remembers the latest hundred ratings in its own storage, in the same best-effort way as the conversation.
|
|
28
|
+
|
|
29
|
+
The widget and the chat inside a page ([React](react.md)) behave the same.
|
|
30
|
+
|
|
31
|
+
## What your function receives
|
|
32
|
+
|
|
33
|
+
| Visitor's action | `rating` | `comment` |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| 👍 | `'up'` | absent |
|
|
36
|
+
| 👎 | `'down'` | absent |
|
|
37
|
+
| 👎, then a comment | `'down'` again, for the same answer | the text |
|
|
38
|
+
| Takes the rating back | `null` | absent |
|
|
39
|
+
|
|
40
|
+
A 👎 arrives at once, and the comment follows as a second report for the same `itemId`, so a visitor who never writes one still counts. Keep the latest report per `conversationId` and `itemId`: a later one replaces the earlier.
|
|
41
|
+
|
|
42
|
+
`conversationId` and `itemId` are the raw OpenAI IDs, so your own code can fetch the conversation for review. They never reach the browser.
|
|
43
|
+
|
|
44
|
+
## Limits and safety
|
|
45
|
+
|
|
46
|
+
- A visitor can rate only answers of their own conversations. Each answer carries an encrypted handle bound to the bot and to the visitor, or to the signed-in user.
|
|
47
|
+
- Ratings are limited to 20 a minute per visitor.
|
|
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
|
+
|
|
50
|
+
## Texts and styling
|
|
51
|
+
|
|
52
|
+
- **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)).
|
|
53
|
+
- **Parts:** `feedback` (the two buttons), `feedback-button` (with `data-rating="up"` or `"down"`, and `aria-pressed`), `feedback-comment`, `feedback-comment-input`, `feedback-comment-actions`, `feedback-skip` and `feedback-send` ([Styling](styling.md)).
|
|
54
|
+
- **In your own markup:** `FeedbackButton` from `@boldare/askdare/react`, and `actions.rate(messageId, rating, comment?)` with `state.commenting` for the question after a 👎.
|
package/docs/getting-started.md
CHANGED
|
@@ -120,5 +120,8 @@ mkdir -p .claude/skills && cp -R node_modules/@boldare/askdare/skills/askdare .c
|
|
|
120
120
|
| Accept images and PDFs | [Attachments](attachments.md) |
|
|
121
121
|
| Let visitors dictate | [Voice input](voice-input.md) |
|
|
122
122
|
| Change texts, language, colors or the button | [Styling](styling.md) and [Themes](themes.md) |
|
|
123
|
+
| Put the chat inside a page of your app, without an iframe | [The chat inside your page](react.md) |
|
|
124
|
+
| Let visitors rate answers | [Answer ratings](feedback.md) |
|
|
125
|
+
| Track costs per turn, or trace with OpenTelemetry | [Observability](observability.md) |
|
|
123
126
|
| Deploy to Vercel or Heroku | [Deployment](deployment.md) |
|
|
124
127
|
| Open the chat to the public | [Going public](going-public.md) |
|
package/docs/going-public.md
CHANGED
|
@@ -77,5 +77,6 @@ export const { GET, POST, DELETE } = createChatHandler({
|
|
|
77
77
|
- [ ] Shared store configured if you run more than one instance.
|
|
78
78
|
- [ ] Instructions contain no secrets.
|
|
79
79
|
- [ ] Privacy notice, retention decision and AI disclosure are in place.
|
|
80
|
+
- [ ] If visitors rate answers, your notice covers their comments, and `onFeedback` keeps them no longer than you need.
|
|
80
81
|
- [ ] You know how to flip `ASKDARE_DISABLED=true` and redeploy or restart, and how long that takes on your host.
|
|
81
82
|
- [ ] `npx @boldare/askdare doctor --url <your app> --env-file <production env>` reports no problems ([Deployment](deployment.md)).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Observability
|
|
2
|
+
|
|
3
|
+
Once the chat is live, you'll want to know what it costs, where a slow answer spent its time, and when something breaks. askdare keeps no database, so it hands each turn to your code instead, through two hooks of `createChatHandler`:
|
|
4
|
+
|
|
5
|
+
| Hook | Receives | For |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| [`onUsage`](configuration.md#onusage) | Every turn: tokens, model, timings, tool calls, outcome | Costs, dashboards, tracing |
|
|
8
|
+
| [`onError`](configuration.md#onerror) | Server errors and errors that end an answer | Error monitoring, such as Sentry |
|
|
9
|
+
|
|
10
|
+
Both may be async. askdare calls them after the answer has streamed, keeps the function alive until they finish, and logs anything they throw by its error's name, so a broken hook never breaks the chat. Neither receives message text: reports carry counters and pseudonyms.
|
|
11
|
+
|
|
12
|
+
Visitors' ratings of answers reach a third hook, `onFeedback`: see [Answer ratings](feedback.md).
|
|
13
|
+
|
|
14
|
+
## Costs per turn
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// app/api/chat/[...path]/route.ts
|
|
18
|
+
import { createChatHandler } from '@boldare/askdare/next';
|
|
19
|
+
import { bots } from '../../../../askdare.config';
|
|
20
|
+
|
|
21
|
+
export const maxDuration = 300;
|
|
22
|
+
|
|
23
|
+
export const { GET, POST, DELETE } = createChatHandler({
|
|
24
|
+
bots,
|
|
25
|
+
onUsage: async ({ bot, model, usage, outcome }) => {
|
|
26
|
+
await metrics.increment('chat.turns', { bot, model, outcome });
|
|
27
|
+
await metrics.increment('chat.input_tokens', usage.inputTokens, { bot, model });
|
|
28
|
+
await metrics.increment('chat.output_tokens', usage.outputTokens, { bot, model });
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Multiply the counters by your model's prices to get money. Cached input is part of the input and usually costs less; reasoning tokens are part of the output. `conversation` is a pseudonym that stays the same for every turn of a conversation, so you can sum a conversation's cost without knowing whose it was. [Costs](costs.md) explains what drives them.
|
|
34
|
+
|
|
35
|
+
## Tracing with OpenTelemetry
|
|
36
|
+
|
|
37
|
+
`@boldare/askdare-otel` turns each report into OpenTelemetry spans, with the attributes of the [GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @boldare/askdare-otel @opentelemetry/api
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { otelUsage } from '@boldare/askdare-otel';
|
|
45
|
+
|
|
46
|
+
export const { GET, POST, DELETE } = createChatHandler({ bots, onUsage: otelUsage() });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Each turn becomes a `chat <model>` span with the token counts, the finish reason and the conversation's pseudonym. Each tool call becomes an `execute_tool <name>` span inside it, marked as an error when it failed or timed out. A turn with several model calls (rounds of tool calls) is one `chat` span with their usage summed.
|
|
50
|
+
|
|
51
|
+
The spans go to whatever tracer provider your app registers. In Next.js that is `instrumentation.ts`, for example with `@vercel/otel`:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// instrumentation.ts
|
|
55
|
+
import { registerOTel } from '@vercel/otel';
|
|
56
|
+
|
|
57
|
+
export function register() {
|
|
58
|
+
registerOTel({ serviceName: 'my-site' });
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Pass `otelUsage({ tracer })` to record with a tracer of your own.
|
|
63
|
+
|
|
64
|
+
The spans are recorded after the turn ends, with its real start and end times, in whatever trace context is active then. With Next.js instrumentation that is the request's trace; otherwise each turn starts a trace of its own.
|
|
65
|
+
|
|
66
|
+
The GenAI conventions are still in development. When they rename an attribute, `@boldare/askdare-otel` follows in a minor release and says so in its changelog.
|
|
67
|
+
|
|
68
|
+
## What the reports contain
|
|
69
|
+
|
|
70
|
+
The full list is in [Configuration](configuration.md#onusage). In short:
|
|
71
|
+
|
|
72
|
+
- **Counted:** input, cached input, cache-write input, output and reasoning tokens; model calls; tool calls with their durations and outcomes.
|
|
73
|
+
- **Identified by pseudonyms:** the conversation and the visitor (or the signed-in user), as HMACs that change when `CHAT_SECRET` rotates.
|
|
74
|
+
- **Never included:** message text, tool arguments or results, file names, IP addresses, raw conversation or visitor IDs.
|
|
75
|
+
|
|
76
|
+
A turn that breaks off mid-answer reports the usage askdare received, which can be a little less than OpenAI bills.
|
package/docs/privacy.md
CHANGED
|
@@ -6,8 +6,9 @@ This page lists what data the chat handles, where it goes and how long it stays,
|
|
|
6
6
|
|
|
7
7
|
| Data | Where | How long |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| A handle to the current conversation (resume token) | The visitor's browser: `localStorage` of your app's origin, inside the chat's iframe | Until the visitor starts a new conversation; it works for at most 30 days |
|
|
10
|
-
|
|
|
9
|
+
| A handle to the current conversation (resume token) | The visitor's browser: `localStorage` of your app's origin, inside the chat's iframe or, for a [chat inside your page](react.md), in the page itself | Until the visitor starts a new conversation; it works for at most 30 days |
|
|
10
|
+
| Which answers the visitor rated 👍 or 👎 | The same `localStorage`, when ratings are on | The latest hundred ratings; never sent anywhere |
|
|
11
|
+
| A session token | The chat's memory (the iframe's, or the page's for a chat inside your page), never stored | 15 minutes |
|
|
11
12
|
| Messages, answers, page context, tool calls and their results | OpenAI, as a conversation in your project | Until deleted |
|
|
12
13
|
| Model responses | OpenAI | OpenAI's retention for stored responses |
|
|
13
14
|
| Uploaded images and PDFs | OpenAI, as files in your project | 30 days, or until the conversation is deleted |
|
|
@@ -15,6 +16,8 @@ This page lists what data the chat handles, where it goes and how long it stays,
|
|
|
15
16
|
| IP addresses, visitor IDs, conversation IDs | Rate-limit counters, in your server's memory or in Upstash | IP addresses up to 2 days, conversation IDs up to 30 days |
|
|
16
17
|
| An HMAC of the visitor or user ID (`safety_identifier`) | Sent to OpenAI with every model request | OpenAI's retention |
|
|
17
18
|
| Error reports | Your server log, or your `onError` function | Your hosting's log retention |
|
|
19
|
+
| Turn reports: token counts, timings, tool names, pseudonyms | Your `onUsage` function, if you set one | Wherever you keep them |
|
|
20
|
+
| Ratings of answers and the comments visitors write | Your `onFeedback` function, if you set one | Wherever you keep them |
|
|
18
21
|
|
|
19
22
|
## In the visitor's browser
|
|
20
23
|
|
|
@@ -25,7 +28,9 @@ The script on your site (`widget.js`) adds the chat button and an iframe. It sto
|
|
|
25
28
|
|
|
26
29
|
### What it stores
|
|
27
30
|
|
|
28
|
-
After the visitor's first message, the chat writes
|
|
31
|
+
After the visitor's first message, the chat writes an entry to `localStorage` for your app's origin: in the iframe's storage for the widget, in your page's own storage for a [chat inside your page](react.md). Nothing is written before that. A second entry follows if the visitor rates an answer.
|
|
32
|
+
|
|
33
|
+
**The conversation**
|
|
29
34
|
|
|
30
35
|
| | |
|
|
31
36
|
| --- | --- |
|
|
@@ -34,15 +39,26 @@ After the visitor's first message, the chat writes one entry to `localStorage`,
|
|
|
34
39
|
| Purpose | To show and continue the conversation after a reload |
|
|
35
40
|
| Lifetime | It works for 30 days after the last answer in the conversation: each answer renews it. It is removed when the visitor starts a new conversation, and when the server says the conversation is gone or the token expired |
|
|
36
41
|
|
|
42
|
+
**Ratings**, only when your route has `onFeedback` and the bot hasn't turned them off with `widget.feedback: false`:
|
|
43
|
+
|
|
44
|
+
| | |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Key | `askdare:<bot id>:ratings` |
|
|
47
|
+
| Value | Which answers this browser rated 👍 or 👎, by a pseudonym of each answer (an HMAC, not the OpenAI ID). No comments, no text, nothing about the visitor |
|
|
48
|
+
| Purpose | To show the visitor's ratings again after a reload |
|
|
49
|
+
| 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 |
|
|
50
|
+
|
|
37
51
|
Everything else stays in memory and disappears with the page: the session token, which lasts 15 minutes, and a signed-in visitor's identity.
|
|
38
52
|
|
|
39
|
-
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 entry off
|
|
53
|
+
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`.
|
|
54
|
+
|
|
55
|
+
**A chat inside your page** has no iframe of its own: its entries sit in your page's `localStorage` beside your own, and scripts on the page can read them, the session token and the conversation. The widget's iframe keeps those from the page. See [the React guide](react.md) for when to keep the widget.
|
|
40
56
|
|
|
41
57
|
### Consent banners
|
|
42
58
|
|
|
43
|
-
Whether
|
|
59
|
+
Whether these entries need the visitor's consent under the rules that apply to you, such as the ePrivacy Directive in the EU, is for you and your legal advisers to decide. These facts are often relevant:
|
|
44
60
|
|
|
45
|
-
-
|
|
61
|
+
- The conversation entry is written only after the visitor sends a message, and only to continue that conversation. The ratings entry is written only when the visitor rates an answer, and only to show that rating again.
|
|
46
62
|
- It isn't used for tracking, analytics or advertising, and it isn't shared with other sites.
|
|
47
63
|
- It contains no readable personal data, and it stops working after 30 days at most.
|
|
48
64
|
|
|
@@ -67,6 +83,8 @@ The server gives every new visitor a random ID: `v_` followed by 32 hexadecimal
|
|
|
67
83
|
- It logs one line per server error: the error code, an explanation of setup problems, and the underlying error, such as OpenAI's status, error code and request ID. It also logs the ID of an uploaded file it couldn't delete.
|
|
68
84
|
- Errors thrown by your own tools are logged as they are. Keep personal data out of their messages.
|
|
69
85
|
- With `onError` in `createChatHandler`, the same reports go to your function, for example to Sentry, instead of the log.
|
|
86
|
+
- With `onUsage`, every turn's report goes to your function: token counts, timings, tool names and outcomes, and pseudonyms (HMACs) of the conversation and the visitor or user. It holds no message text. See [Observability](observability.md).
|
|
87
|
+
- With `onFeedback`, visitors can rate answers, and each rating goes to your function with the comment the visitor wrote, the OpenAI conversation and answer IDs, a pseudonym of the visitor, and the signed-in user if there is one. askdare keeps none of it. A comment is free text the visitor typed, so treat it like a message: mention it in your notice and keep it no longer than you need. The visitor's browser also remembers which answers they rated 👍 or 👎 (not the comments), next to the conversation in its storage (see [What it stores](#what-it-stores)). See [Answer ratings](feedback.md).
|
|
70
88
|
- Your hosting provider may log every request, IP addresses included, according to its own settings.
|
|
71
89
|
|
|
72
90
|
### `safety_identifier`
|
|
@@ -145,6 +163,7 @@ The note exists for the transparency duty in Article 50 of the EU AI Act: people
|
|
|
145
163
|
| Upstash | With `@boldare/askdare-upstash` | Rate-limit counters, whose names hold IP addresses, visitor IDs and conversation IDs |
|
|
146
164
|
| Your hosting provider, such as Vercel or Heroku | Always | Every request to the app, with IP addresses, and the server log |
|
|
147
165
|
| Your error monitoring | With `onError` | Error reports, without message contents or API keys |
|
|
166
|
+
| Your metrics or tracing | With `onUsage`, e.g. through `@boldare/askdare-otel` | Turn reports: counters, timings and pseudonyms, without message text |
|
|
148
167
|
|
|
149
168
|
Your tools may send data to further services of your own.
|
|
150
169
|
|
|
@@ -169,7 +188,8 @@ There is no previous-secret setting for `IDENTITY_SECRET`. When you change it:
|
|
|
169
188
|
|
|
170
189
|
- [ ] Name OpenAI, and Upstash if you use it, as processors, and your hosting provider.
|
|
171
190
|
- [ ] Say that conversations, including what visitors type and attach, are stored by OpenAI until deleted, and how visitors delete them.
|
|
172
|
-
- [ ] Describe the `localStorage`
|
|
191
|
+
- [ ] Describe the `localStorage` entries and their purpose: the conversation, and the ratings if you use `onFeedback`.
|
|
192
|
+
- [ ] If you collect ratings, say that visitors' comments reach you and how long you keep them.
|
|
173
193
|
- [ ] Mention IP addresses in rate limits and their retention.
|
|
174
194
|
- [ ] Decide on a retention policy for conversations.
|
|
175
195
|
- [ ] Keep the AI disclosure, and link this notice from it with `privacyUrl`.
|
package/docs/protocol.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Wire protocol (version 1)
|
|
2
2
|
|
|
3
|
-
This is how the askdare server streams a chat turn to its clients: the
|
|
3
|
+
This is how the askdare server streams a chat turn to its clients: the widget's iframe app and `@boldare/askdare/react`. The protocol belongs to askdare; raw OpenAI stream events are never forwarded ([ADR-0002](https://github.com/boldare/askdare/blob/main/docs/adr/0002-openai-only-no-leaked-types.md)).
|
|
4
4
|
|
|
5
5
|
Source of truth: `packages/askdare/src/protocol/`.
|
|
6
6
|
|
|
@@ -17,13 +17,14 @@ Every path sits under the route's base path: `/api/chat` by default, or `basePat
|
|
|
17
17
|
| `POST /session` | None | Starts or renews a visitor's session and answers an access token ([Identity](#identity)) |
|
|
18
18
|
| `POST /messages` | Access token | Sends a message and answers with the event stream ([Events](#events)) |
|
|
19
19
|
| `POST /history` | Access token | The visible messages of the visitor's conversation |
|
|
20
|
+
| `POST /feedback` | Access token | Rates one answer ([Feedback](#feedback)) |
|
|
20
21
|
| `DELETE /conversation` | Access token | Deletes the visitor's conversation, and its files when the bot accepts attachments |
|
|
21
22
|
| `POST /attachments` | Access token | Uploads one file ([Attachments](#attachments)) |
|
|
22
23
|
| `POST /transcriptions` | Access token | Transcribes one dictation ([Dictation](#dictation)) |
|
|
23
24
|
| `POST /doctor` | Doctor token | Checks the setup for `askdare doctor` ([Diagnostics](#diagnostics)) |
|
|
24
25
|
|
|
25
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.
|
|
26
|
-
- **`POST /history`** takes `{ "botId", "resumeToken" }` and answers `{ "messages": [{ "id", "role", "text", "citations", "attachments" }] }`, where `attachments` is a count.
|
|
27
|
+
- **`POST /history`** takes `{ "botId", "resumeToken" }` and answers `{ "messages": [{ "id", "role", "text", "citations", "attachments", "feedback"? }] }`, where `attachments` is a count and `feedback` is the answer's rating handle (see [Feedback](#feedback)).
|
|
27
28
|
- **`DELETE /conversation`** takes the same body and answers `204` with no body.
|
|
28
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.
|
|
29
30
|
|
|
@@ -51,7 +52,7 @@ Every path sits under the route's base path: `/api/chat` by default, or `basePat
|
|
|
51
52
|
| `text.delta` | `messageId`, `delta` | Append text to the reply (markdown) |
|
|
52
53
|
| `citation` | `messageId`, `index`, `title`, `url?` | Source for marker `[index]`; `url` is http(s) only |
|
|
53
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 |
|
|
54
|
-
| `message.end` | `messageId`, `reason`, `resumeToken?` | The reply finished. A resumed conversation gets a fresh `resumeToken`, so it stays reachable 30 days after its last message. Reasons: `completed`, `max_steps`, `max_output_tokens`, `timeout`, `content_filter`, `aborted` |
|
|
55
|
+
| `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` |
|
|
55
56
|
| `error` | `code`, `message`, `retryAfterMs?`, `key?`, `params?` | The turn failed; `message` is safe to show ([keys and parameters](#error-keys-and-parameters)) |
|
|
56
57
|
|
|
57
58
|
## Attachments
|
|
@@ -67,6 +68,15 @@ When a bot has `attachments` enabled, files travel separately from the message:
|
|
|
67
68
|
|
|
68
69
|
When a bot has `voice` enabled, `POST /transcriptions` takes a recording as the raw body (`Content-Type: application/octet-stream`) with the `Bearer` token and two headers: `x-askdare-bot` (bot ID) and `x-askdare-languages` (comma-separated language tags, used as hints). It answers `{ "text": "…" }`. Clients put the text in the message field for the visitor to check; nothing is sent to the model.
|
|
69
70
|
|
|
71
|
+
## Feedback
|
|
72
|
+
|
|
73
|
+
When the app sets `onFeedback` and the bot allows it, every answer comes with a rating handle: in `message.end` while it streams, and on assistant messages in `POST /history`. A handle is `{ "handle", "key" }`:
|
|
74
|
+
|
|
75
|
+
- `handle` is opaque and encrypted, bound to the bot and to the visitor or signed-in user. It holds the conversation and the answer, which the client never sees.
|
|
76
|
+
- `key` is a hex string that stays the same for the answer across reloads, so a client can remember the visitor's own rating.
|
|
77
|
+
|
|
78
|
+
`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
|
+
|
|
70
80
|
## Identity
|
|
71
81
|
|
|
72
82
|
`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)).
|