@boldare/askdare 0.3.0-rc.0 → 0.4.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/dist/store.d.ts CHANGED
@@ -189,9 +189,9 @@ interface ToolContext {
189
189
  type Jsonified<T> = T extends {
190
190
  toJSON(): infer R;
191
191
  } ? Jsonified<R> : T extends bigint | symbol | ((...args: never[]) => unknown) | undefined ? never : T extends readonly (infer Item)[] ? Jsonified<Item>[] : T extends object ? { [Key in keyof T as Jsonified<T[Key]> extends never ? never : Key]: Jsonified<T[Key]>; } : T;
192
- interface ToolDefinition<Input extends z.ZodObject, Output = unknown> {
192
+ interface ToolDefinition<Input extends z.ZodObject, Output = unknown, Ui = unknown, Name extends string = string> {
193
193
  /** Name the model calls, 1–64 letters, digits, `_` or `-`. */
194
- readonly name: string;
194
+ readonly name: Name;
195
195
  /** Tells the model when and how to use the tool. */
196
196
  readonly description: string;
197
197
  /**
@@ -212,20 +212,34 @@ interface ToolDefinition<Input extends z.ZodObject, Output = unknown> {
212
212
  * several calls of a turn define them, the last one wins.
213
213
  */
214
214
  readonly replies?: (output: Jsonified<Output>) => readonly string[] | undefined;
215
+ /**
216
+ * What the visitor may see of a successful result, for a component the site registers with
217
+ * `toolRenderers` (ADR-0017). Only this reaches the browser, never the result itself, so pick
218
+ * the fields a visitor may see. It gets the result as the model received it, parsed back from
219
+ * JSON, and runs again on every reload, so keep it pure: the same result, the same payload.
220
+ * Return plain JSON of at most 8 KB and 8 levels, or `undefined` or `null` for none; a payload
221
+ * over a limit is dropped whole. An answer shows at most 4, in call order.
222
+ */
223
+ readonly ui?: (output: Jsonified<Output>) => Ui | null | undefined;
215
224
  }
216
- interface Tool {
217
- readonly name: string;
225
+ /**
226
+ * A tool the bot can call. `Name` and `Ui` carry the tool's name and the type its `ui` returns,
227
+ * so a page can type its renderers with `import type` (ADR-0017).
228
+ */
229
+ interface Tool<Name extends string = string, Ui = unknown> {
230
+ readonly name: Name;
218
231
  readonly description: string;
219
232
  readonly input: z.ZodObject;
220
233
  readonly execute: (input: unknown, context: ToolContext) => unknown;
221
234
  readonly timeoutMs: number;
222
235
  readonly replies?: ((output: unknown) => readonly string[] | undefined) | undefined;
236
+ readonly ui?: ((output: unknown) => Ui | null | undefined) | undefined;
223
237
  }
224
238
  /**
225
239
  * Declares a server-side function the model may call. Arguments are validated with the schema
226
240
  * before `execute` runs; failures are reported to the model, never to the visitor.
227
241
  */
228
- declare function defineTool<Input extends z.ZodObject, Output = unknown>(definition: ToolDefinition<Input, Output>): Tool;
242
+ declare function defineTool<Input extends z.ZodObject, Output = unknown, Ui = never, const Name extends string = string>(definition: ToolDefinition<Input, Output, Ui, Name>): Tool<Name, Ui>;
229
243
  /** Per-request context available when building instructions. */
230
244
  interface BotContext {
231
245
  /** Validated BCP 47 tag chosen by the widget. */
@@ -303,6 +317,8 @@ interface VoiceConfig {
303
317
  /** Longest dictation; recording stops by itself at this point. Default 60 seconds. */
304
318
  readonly maxSeconds?: number;
305
319
  }
320
+ /** Overrides for the texts the chat shows, by key (see the dictionary in the docs). */
321
+ type WidgetTexts = Readonly<Partial<Record<TextKey, string>>>;
306
322
  /** Public widget settings. Everything here is sent to browsers, so never put secrets in it. */
307
323
  interface WidgetConfig {
308
324
  /** Shortcut for `texts['header.title']`. */
@@ -319,8 +335,13 @@ interface WidgetConfig {
319
335
  * Polish; other languages show English unless you set `texts`. Default `en`.
320
336
  */
321
337
  readonly locale?: string;
322
- /** Overrides for any text the widget shows, by key (see the dictionary in the docs). */
323
- readonly texts?: Readonly<Partial<Record<TextKey, string>>>;
338
+ /**
339
+ * Overrides for any text the widget shows, by key (see the dictionary in the docs). Either one
340
+ * set for every language (`{ 'launcher.label': 'Questions?' }`), or one set per language
341
+ * (`{ en: {...}, pl: {...} }`): a visitor gets the set for their language tag, else one for
342
+ * the same language, and a language without a built-in dictionary gets the `en` set.
343
+ */
344
+ readonly texts?: WidgetTexts | Readonly<Record<string, WidgetTexts>>;
324
345
  /**
325
346
  * The note that visitors are talking to an AI (EU AI Act, art. 50), shown under the message
326
347
  * field, with an optional link to your privacy policy (an https URL or a path on your app).
@@ -372,8 +393,13 @@ interface BotWidget {
372
393
  readonly replies: "suggest" | "off";
373
394
  readonly avatar: string | undefined;
374
395
  readonly launcherLabel: string;
375
- /** Text overrides, including the title, greeting, placeholder and launcher label shortcuts. */
376
- readonly texts: Readonly<Partial<Record<TextKey, string>>>;
396
+ /**
397
+ * Text overrides for every language, including the title, greeting, placeholder and launcher
398
+ * label shortcuts.
399
+ */
400
+ readonly texts: WidgetTexts;
401
+ /** Text overrides per language, by canonical BCP 47 tag; they win over `texts`. */
402
+ readonly textsByLocale: Readonly<Record<string, WidgetTexts>>;
377
403
  readonly disclosure: false | {
378
404
  readonly privacyUrl: string | undefined;
379
405
  };
@@ -409,6 +435,13 @@ interface BotDefinition {
409
435
  readonly voice?: VoiceConfig | undefined;
410
436
  readonly security?: BotSecurity;
411
437
  readonly widget?: WidgetConfig;
438
+ /**
439
+ * A page of this app to show in the widget's iframe instead of askdare's own, such as
440
+ * `/askdare/support` (ADR-0018): the chat route redirects the iframe there. Render it with
441
+ * `EmbedRoot` from `@boldare/askdare/embed` and `getEmbedConfig`, and send `embedPageHeaders`
442
+ * with it. Off when absent: askdare's page, which needs nothing from you.
443
+ */
444
+ readonly embedPath?: string | undefined;
412
445
  }
413
446
  interface Bot {
414
447
  readonly id: string;
@@ -424,6 +457,7 @@ interface Bot {
424
457
  readonly allowedOrigins: readonly string[];
425
458
  };
426
459
  readonly widget: BotWidget;
460
+ readonly embedPath: string | undefined;
427
461
  }
428
462
  /**
429
463
  * Declares a chatbot. Validates eagerly so misconfiguration fails at startup, not on the first
@@ -0,0 +1,130 @@
1
+
2
+ import { ComponentProps, ComponentType, ReactElement } from "react";
3
+ declare const PRESET_NAMES: readonly ["halo", "aura", "sage", "care"];
4
+ type PresetName = (typeof PRESET_NAMES)[number];
5
+ /** Component variants a preset picks; each becomes a `data-ask-*` attribute on the document. */
6
+ interface ThemeVariants {
7
+ readonly avatar: "orb" | "icon" | "initials" | "none";
8
+ readonly welcome: "hero" | "persona" | "intro";
9
+ readonly launcher: "orb" | "circle" | "pill";
10
+ readonly bubbles: "filled" | "plain";
11
+ readonly surface: "solid" | "glass";
12
+ readonly density: "comfortable" | "compact";
13
+ readonly composer: "outline" | "gradient";
14
+ /** Where the latest answer's options show: under it, or in one row above the message field. */
15
+ readonly replies: "answer" | "composer";
16
+ }
17
+ /** What a visitor may attach, as the bot allows it. */
18
+ interface ChatAttachments {
19
+ readonly images: boolean;
20
+ readonly pdf: boolean;
21
+ readonly maxBytes: number;
22
+ readonly maxPerMessage: number;
23
+ readonly maxPdfPages: number;
24
+ }
25
+ /** A bot's public widget settings, in the visitor's language. */
26
+ interface ChatWidget {
27
+ readonly title: string;
28
+ readonly subtitle: string;
29
+ readonly greeting: string;
30
+ readonly placeholder: string;
31
+ /** The language this visitor sees. */
32
+ readonly locale: string;
33
+ readonly starters: readonly string[];
34
+ readonly avatar: string | undefined;
35
+ readonly launcherLabel: string;
36
+ readonly disclosure: false | {
37
+ readonly privacyUrl: string | undefined;
38
+ };
39
+ readonly preset: PresetName;
40
+ readonly variants: ThemeVariants;
41
+ /** `auto` follows the visitor's system setting. */
42
+ readonly colorScheme: "auto" | "light" | "dark";
43
+ /** Every text in the visitor's language, overrides applied; plural keys included. */
44
+ readonly texts: Readonly<Record<string, string>>;
45
+ }
46
+ /** Stylesheets of a chat inside a page, served by the chat route (ADR-0011). */
47
+ interface ChatStyles {
48
+ /** The bot's tokens for both color schemes, then its own `widget.css`. */
49
+ readonly theme: string;
50
+ /** The default look; only `DefaultChat` loads it. */
51
+ readonly skin: string;
52
+ /** `@font-face` rules of the built-in themes; browsers fetch only the fonts in use. */
53
+ readonly fonts: string;
54
+ }
55
+ /** What the browser needs to run one bot's chat. Public: it never holds secrets (ADR-0008). */
56
+ interface ChatConfig {
57
+ readonly protocolVersion: number;
58
+ /** Path of the chat route, such as `/api/chat`. Same origin only (ADR-0011). */
59
+ readonly basePath: string;
60
+ readonly botId: string;
61
+ readonly widget: ChatWidget;
62
+ /** Whether the bot accepts a description of the page it is on. */
63
+ readonly pageContext: boolean;
64
+ /** Whether the bot lets visitors rate answers. Answers carry a handle when the route takes ratings. */
65
+ readonly feedback: boolean;
66
+ /** Absent when attachments are off. */
67
+ readonly attachments?: ChatAttachments;
68
+ /** Absent when voice input is off. The model stays on the server. */
69
+ readonly voice?: {
70
+ readonly maxSeconds: number;
71
+ };
72
+ /** From `getChatConfig`, for a chat inside a page. The iframe links its own stylesheets. */
73
+ readonly styles?: ChatStyles;
74
+ }
75
+ /** What `EmbedRoot` from `@boldare/askdare/embed` needs; `getEmbedConfig` builds it (ADR-0018). */
76
+ interface EmbedChatConfig extends ChatConfig {
77
+ /** Origins whose pages may hand the chat its connection to the loader (ADR-0005). */
78
+ readonly allowedOrigins: readonly string[];
79
+ /** `inline` inside an element of the host page, `floating` in the widget's panel. */
80
+ readonly mode: "floating" | "inline";
81
+ }
82
+ /**
83
+ * What a tool's `ui` returns, read from its type (`typeof myTool`) with `import type`, so no server
84
+ * code reaches the page. Structural, so the page needs only the tool's type.
85
+ */
86
+ type ToolData<T> = T extends {
87
+ readonly ui?: ((output: never) => infer Ui) | undefined;
88
+ } ? Exclude<Ui, null | undefined> : never;
89
+ /** Any tool: without a type argument, a component gets `data: unknown` and any name. */
90
+ interface AnyTool {
91
+ readonly name: string;
92
+ readonly ui?: ((output: never) => unknown) | undefined;
93
+ }
94
+ /** What a component registered for a tool gets (ADR-0017). */
95
+ interface ToolRendererProps<T extends {
96
+ readonly name: string;
97
+ } = AnyTool> {
98
+ /** What the tool's `ui` picked from its result: plain JSON. Render it as text, never as HTML. */
99
+ readonly data: ToolData<T>;
100
+ /** The tool's name. */
101
+ readonly name: T["name"];
102
+ /** The call, stable for the answer. */
103
+ readonly callId: string;
104
+ }
105
+ /**
106
+ * Components by tool name for `Root`'s `toolRenderers`. Without a type argument, any component per
107
+ * name; with your tools, each component checked against its tool's payload:
108
+ * `{ find_slots: SlotList } satisfies ToolRenderers<[typeof findSlots]>`.
109
+ */
110
+ type ToolRenderers<Tools extends readonly {
111
+ readonly name: string;
112
+ }[] = never> = [Tools] extends [never] ? Readonly<Record<string, ComponentType<ToolRendererProps<never>>>> : { readonly [T in Tools[number] as T["name"]]?: ComponentType<ToolRendererProps<T>>; };
113
+ type ToolResultsProps = ComponentProps<"div">;
114
+ /**
115
+ * The current message's tool payloads (ADR-0017), each drawn by the component registered for its
116
+ * tool in `Root`'s `toolRenderers`, in call order: a group (`tool-results`) of cards
117
+ * (`tool-result`, with `data-ask-tool`). A payload without a component shows nothing, and when
118
+ * `toolRenderers` is set the console says so once per tool. Use it inside `MessageList`.
119
+ */
120
+ declare function ToolResults(props: ToolResultsProps): ReactElement | null;
121
+ type LinkProps = Omit<ComponentProps<"a">, "href" | "target" | "rel"> & {
122
+ readonly href: string;
123
+ };
124
+ /**
125
+ * A link for a URL from a tool's payload: only `https:`, `http:` and `mailto:`, opened in a new
126
+ * tab, as links in answers are. Any other URL (`javascript:`, `data:`, a relative path) renders
127
+ * the text alone.
128
+ */
129
+ declare function Link({ href, children, ...props }: LinkProps): ReactElement;
130
+ export { ToolResults as a, ChatConfig as c, EmbedChatConfig as d, PresetName as f, ToolRenderers as i, ChatStyles as l, LinkProps as n, ToolResultsProps as o, ThemeVariants as p, ToolRendererProps as r, ChatAttachments as s, Link as t, ChatWidget as u };
@@ -1,4 +1,4 @@
1
- /* Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change. */
1
+ /* Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change. */
2
2
  /*
3
3
  * Default skin of the chat (ADR-0008, ADR-0011), in the iframe and inside a page. Everything is
4
4
  * built on the public styling API: the --ask-* tokens (set per bot by the theme stylesheet), the
@@ -523,6 +523,18 @@
523
523
  font-size: 0.8rem;
524
524
  }
525
525
 
526
+ /* Tool cards (ADR-0017): the cards are the site's components; the skin only spaces them. */
527
+ [data-ask-part="tool-results"]:where([data-ask-skin] *) {
528
+ display: grid;
529
+ gap: 8px;
530
+ min-width: 0;
531
+ }
532
+
533
+ [data-ask-part="tool-result"]:where([data-ask-skin] *) {
534
+ min-width: 0;
535
+ overflow-wrap: anywhere;
536
+ }
537
+
526
538
  [data-ask-part="citations"]:where([data-ask-skin] *) {
527
539
  display: flex;
528
540
  flex-wrap: wrap;
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import type { ReactElement } from 'react';
3
3
  import { useSkin } from './context';
4
4
  import { SparkIcon } from './icons';
package/dist/ui/chat.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  'use client';
3
3
 
4
4
  // The entry of an ejected copy (`npx @boldare/askdare add ui`): the same DefaultChat as in
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.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 KeyboardEvent, type ReactElement, useEffect, useId, useRef } from 'react';
4
4
  import { RestartIcon } from './icons';
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import type { ChatBot, Translate } from '@boldare/askdare/react';
3
3
  import { type Context, createContext, type RefObject, useContext } from 'react';
4
4
 
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import { FeedbackButton, useChat, useChatState, useMessage } from '@boldare/askdare/react';
3
3
  import { type FormEvent, type ReactElement, useEffect, useId, useRef, useState } from 'react';
4
4
  import { useSkin } from './context';
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import {
3
3
  AttachButton,
4
4
  Composer,
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.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 } from 'react';
4
4
  import { Avatar } from './avatar';
package/dist/ui/icons.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import type { ReactElement, ReactNode } from 'react';
3
3
 
4
4
  /** Line icons on a 24px grid, drawn with the current text color. */
package/dist/ui/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  'use client';
3
3
 
4
4
  // The default look of the chat (ADR-0011): what `npx @boldare/askdare add ui` copies into an app.
@@ -1,10 +1,11 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import {
3
3
  Citations,
4
4
  Message,
5
5
  MessageFiles,
6
6
  MessageText,
7
7
  QuickReplies,
8
+ ToolResults,
8
9
  useMessage,
9
10
  } from '@boldare/askdare/react';
10
11
  import type { ReactElement } from 'react';
@@ -13,9 +14,9 @@ import { useSkin } from './context';
13
14
  import { Feedback } from './feedback';
14
15
 
15
16
  /**
16
- * One message: the assistant's face beside its answers, then text, files, sources, rating and,
17
- * under the latest answer, the options the visitor can click (unless the theme puts them above
18
- * the message field).
17
+ * One message: the assistant's face beside its answers, then text, tool cards, files, sources,
18
+ * rating and, under the latest answer, the options the visitor can click (unless the theme puts
19
+ * them above the message field).
19
20
  */
20
21
  export function DefaultMessage(): ReactElement {
21
22
  const message = useMessage();
@@ -25,6 +26,7 @@ export function DefaultMessage(): ReactElement {
25
26
  {message.role === 'assistant' && <Avatar size="small" />}
26
27
  <div data-ask-part="message-body">
27
28
  <MessageText />
29
+ <ToolResults />
28
30
  <MessageFiles />
29
31
  <Citations />
30
32
  <Feedback />
package/dist/ui/panel.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
2
2
  import {
3
3
  ErrorMessage,
4
4
  MessageList,
@@ -6,6 +6,7 @@ import {
6
6
  Panel,
7
7
  Status,
8
8
  useChat,
9
+ useFrame,
9
10
  } from '@boldare/askdare/react';
10
11
  import {
11
12
  type ComponentType,
@@ -34,23 +35,31 @@ export interface DefaultChatComponents {
34
35
  }
35
36
 
36
37
  export interface DefaultPanelProps {
37
- /** Level of the chat's title (default 2); 1 makes the chat the page's main landmark. */
38
+ /**
39
+ * Level of the chat's title (default 2, or 1 inside `EmbedRoot`); 1 makes the chat the page's
40
+ * main landmark.
41
+ */
38
42
  readonly headingLevel?: 1 | 2 | 3 | 4 | 5;
39
- /** Shows a close button, and Escape calls it too. */
43
+ /** Shows a close button, and Escape calls it too. Inside `EmbedRoot`, it closes the widget by default. */
40
44
  readonly onClose?: (() => void) | undefined;
41
45
  readonly components?: DefaultChatComponents | undefined;
42
46
  }
43
47
 
44
48
  /** The default look of the chat inside its frame: header, conversation and message field. */
45
49
  export function DefaultPanel({
46
- headingLevel = 2,
47
- onClose,
50
+ headingLevel: level,
51
+ onClose: close,
48
52
  components = {},
49
- ownsDocument = false,
53
+ ownsDocument: owns = false,
50
54
  }: DefaultPanelProps & {
51
55
  /** The chat is the whole document, as in its iframe: Escape works wherever focus is. */
52
56
  readonly ownsDocument?: boolean;
53
57
  }): ReactElement {
58
+ // On a site's own page in the widget's iframe (EmbedRoot), the chat is the document there too.
59
+ const frame = useFrame();
60
+ const headingLevel = level ?? (frame ? 1 : 2);
61
+ const onClose = close ?? frame?.close;
62
+ const ownsDocument = owns || frame !== null;
54
63
  const { state, actions, bot, t } = useChat();
55
64
  const [confirming, setConfirming] = useState(false);
56
65
  /** Accepted, and the server is deleting the conversation: the question stays, busy, until then. */
@@ -1,4 +1,4 @@
1
- // Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
1
+ // Ejected from @boldare/askdare@0.4.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/cli.md CHANGED
@@ -121,6 +121,7 @@ Without `--env-file`, `doctor` reads the environment the way `next dev` does: va
121
121
  | Attachments | Only with `attachments`: the key can upload and delete a small file. | Files: Write |
122
122
  | Headers | `widget.js?bot=<id>` answers with JavaScript, and the chat page answers without a redirect, without `X-Frame-Options` and with exactly one `frame-ancestors`. It lists the sites that may embed the chat, and warns when something sets cookies. | |
123
123
  | `--origin` | The site is the app itself or is in the bot's `security.allowedOrigins`. | |
124
+ | Your own page | Only with `embedPath`: the chat page redirects to it, and the page answers without a redirect (a login or a `proxy.ts` rewrite), renders `EmbedRoot`, has exactly one `frame-ancestors` that lists the app and every allowed origin and nothing more, and keeps the microphone off for a bot without voice input. The fixes name `embedPageHeaders`. | |
124
125
  | Timeout | The route's `maxDuration` is at least the bot's `limits.turnTimeoutMs` plus 15 seconds. Otherwise it's a warning. | |
125
126
 
126
127
  `doctor` also says when OpenAI rejects the key, or when the project is out of credit. Each run makes a few small OpenAI requests per bot, and everything it creates is deleted straight away. The app accepts one run at a time, and at most 3 a minute.
@@ -86,6 +86,7 @@ export const { GET, POST, DELETE } = createChatHandler({
86
86
  | `attachments` | `AttachmentConfig` | off | Images and PDFs from visitors. See [Attachments](#attachments). |
87
87
  | `voice` | `VoiceConfig` | off | Dictation. See [Voice](#voice). |
88
88
  | `security` | `BotSecurity` | own origin only | Sites that may embed the chat. See [Security](#security). |
89
+ | `embedPath` | `string` | off: askdare's own page | A page of this app to show in the widget's iframe instead of askdare's, such as `/askdare/support`. A path of the app, outside the chat route, without a query, a fragment or `.`/`..` segments. See [Your own page in the iframe](#your-own-page-in-the-iframe). |
89
90
  | `limits` | `BotLimits` | see [Limits](#limits) | Rates and budgets. |
90
91
  | `widget` | `WidgetConfig` | see [Widget](#widget) | Texts, language and look. |
91
92
 
@@ -150,6 +151,16 @@ The list holds at most 50 origins. Duplicates are dropped. A wrong entry fails w
150
151
 
151
152
  To check that a site may embed the chat, run `npx @boldare/askdare doctor --origin https://www.example.com`.
152
153
 
154
+ ### Your own page in the iframe
155
+
156
+ By default the widget's iframe shows askdare's own page, which needs nothing from you. With `embedPath`, it shows a page of your app instead, so the widget on other sites can use your own components and [tool cards](react.md#tool-cards) ([ADR-0018](https://github.com/boldare/askdare/blob/main/docs/adr/0018-embed-path.md)). The chat route redirects the iframe to that path, with the visitor's language (`lang`, for a bot with `locale: 'auto'`) and the mode (`mode=inline`) in the query; the loader on the embedding site doesn't change. The redirect goes to `embedPath` exactly as you write it, so in an app with `basePath` in `next.config.ts` include that prefix (`/help/askdare/support`).
157
+
158
+ The page must send the headers askdare's own page sends. `@boldare/askdare/next` gives you both halves:
159
+ - `getEmbedConfig({ bots, bot, searchParams })` reads the language and the mode from the page's search parameters and returns the bot's public configuration, its allowed origins and the mode.
160
+ - `embedPageHeaders({ bots, bot })` returns the page's headers: `frame-ancestors` with the app and `security.allowedOrigins`, a `Permissions-Policy` that keeps the microphone off unless the bot has voice input, and `Referrer-Policy: strict-origin`. Send them from `proxy.ts`.
161
+
162
+ The page renders `EmbedRoot` from `@boldare/askdare/embed`. [Embedding: your own page in the iframe](embedding.md#your-own-page-in-the-iframe) walks through it. `npx @boldare/askdare doctor` follows the redirect and checks the page: no login or redirect in front of it, `EmbedRoot` on it, who may frame it and the microphone rule.
163
+
153
164
  ### Limits
154
165
 
155
166
  Limits bound what visitors can cost ([ADR-0004](https://github.com/boldare/askdare/blob/main/docs/adr/0004-threat-model.md)). Every limit applies per bot, and every value is a whole number.
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 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.
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
package/docs/embedding.md CHANGED
@@ -216,6 +216,108 @@ An inline chat inside a React app has a hydration caveat. [Styling](styling.md#3
216
216
 
217
217
  In the Next.js app that serves the chat, you can also render it without an iframe, as React components in your own pages: see [The chat inside your page](react.md).
218
218
 
219
+ ## Your own page in the iframe
220
+
221
+ By default the widget's iframe shows askdare's own page, built with the default look: it needs nothing from you and nothing on your side can break it. A bot can show a page of your app there instead, so the widget on every site that embeds it uses your own components and draws your [tool cards](react.md#tool-cards) ([ADR-0018](https://github.com/boldare/askdare/blob/main/docs/adr/0018-embed-path.md)). The snippet on those sites stays the same.
222
+
223
+ **1. Point the bot at a page.** A path of your app, outside the chat route:
224
+
225
+ ```ts
226
+ // askdare.config.ts
227
+ defineBot({ id: 'support', /* … */ embedPath: '/askdare/support' });
228
+ ```
229
+
230
+ The chat route now redirects the iframe there, with `lang` (for a bot with `locale: 'auto'`) and `mode=inline` (for an inline chat) in the query.
231
+
232
+ **2. Give the page its own root layout.** Put it in a route group with its own `<html>` and `<body>`, so nothing of your site (its header, navigation, fonts, analytics or chat widget) renders or runs inside the widget on other sites. With a group of its own, your other pages move into a group too, such as `app/(site)/`:
233
+
234
+ ```tsx
235
+ // app/(askdare)/layout.tsx
236
+ import './frame.css'; // html, body { height: 100%; margin: 0 }
237
+
238
+ export default function FrameLayout({ children }: { readonly children: React.ReactNode }) {
239
+ return (
240
+ <html lang="en">
241
+ <body>{children}</body>
242
+ </html>
243
+ );
244
+ }
245
+ ```
246
+
247
+ **3. Render the chat with `EmbedRoot`.** The page reads its configuration in a Server Component; a client component renders it:
248
+
249
+ ```tsx
250
+ // app/(askdare)/askdare/support/page.tsx
251
+ import { getEmbedConfig } from '@boldare/askdare/next';
252
+ import { Suspense } from 'react';
253
+ import { bots } from '@/askdare.config';
254
+ import { FramedChat } from './framed-chat';
255
+
256
+ type Search = Promise<Record<string, string | string[] | undefined>>;
257
+
258
+ export default function Page({ searchParams }: { searchParams: Search }) {
259
+ // With Cache Components (as in the starter), the request's data is read inside Suspense.
260
+ return (
261
+ <Suspense>
262
+ <Chat searchParams={searchParams} />
263
+ </Suspense>
264
+ );
265
+ }
266
+
267
+ async function Chat({ searchParams }: { searchParams: Search }) {
268
+ const config = getEmbedConfig({ bots, bot: 'support', searchParams: await searchParams });
269
+ return <FramedChat config={config} />;
270
+ }
271
+ ```
272
+
273
+ ```tsx
274
+ // app/(askdare)/askdare/support/framed-chat.tsx
275
+ 'use client';
276
+ import { type EmbedChatConfig, EmbedRoot } from '@boldare/askdare/embed';
277
+ import * as Chat from '@boldare/askdare/react';
278
+ import { toolRenderers } from '@/components/tool-cards';
279
+
280
+ export function FramedChat({ config }: { config: EmbedChatConfig }) {
281
+ return (
282
+ <EmbedRoot config={config} toolRenderers={toolRenderers}>
283
+ <Chat.DefaultChat className="framed-chat" />
284
+ </EmbedRoot>
285
+ );
286
+ }
287
+ ```
288
+
289
+ `EmbedRoot` connects to the loader on the embedding site exactly as askdare's own page does: `askdare('identify')`, `configure`, `on`, opening, closing and language switches all work. Inside it, `DefaultChat` is the page's main landmark with an `h1`, and shows a close button. Instead of `DefaultChat`, you can use an [ejected copy](react.md#eject-the-default-look), which behaves the same, or [your own markup](react.md#your-own-markup), where `useFrame()` gives you the close action for your own button.
290
+
291
+ **4. Send the iframe page's headers.** Without them, any site could frame the page, and the microphone would follow your app's policy. Set them in `proxy.ts`, per request:
292
+
293
+ ```ts
294
+ // proxy.ts
295
+ import { embedPageHeaders } from '@boldare/askdare/next';
296
+ import { type NextRequest, NextResponse } from 'next/server';
297
+ import { bots } from './askdare.config';
298
+
299
+ export function proxy(request: NextRequest) {
300
+ const response = NextResponse.next();
301
+ const bot = bots.find((item) => item.embedPath === request.nextUrl.pathname);
302
+ for (const { key, value } of bot ? embedPageHeaders({ bots, bot: bot.id }) : []) {
303
+ response.headers.set(key, value);
304
+ }
305
+ return response;
306
+ }
307
+
308
+ export const config = { matcher: '/askdare/:bot' };
309
+ ```
310
+
311
+ Not `headers()` in `next.config.ts`, unless the allowed origins are written in your code: Next.js evaluates it when the app is built, so origins from the environment where it runs would be missing, and the widget wouldn't open on those sites. If you already have a `proxy.ts` that signs visitors in or rewrites paths (i18n), leave the page's path out of what it does: the page must answer without a redirect.
312
+
313
+ **5. Check it.** Run `npx @boldare/askdare doctor --origin https://www.example.com`. It follows the redirect and checks the page: it answers without a redirect, renders `EmbedRoot`, may be framed by the app and every allowed origin and by nothing else, and keeps the microphone off unless the bot has voice input.
314
+
315
+ Things to know:
316
+ - **The page runs your scripts with the chat's origin,** as [the chat inside your page](react.md) does: they could read the visitor's session. Load no third-party scripts on it; the root layout of its own keeps your site's out.
317
+ - **The page is rendered per request** (it reads its search parameters). Don't cache it.
318
+ - **It opens a moment later** than askdare's own page: one redirect, and your page hydrates before the chat connects. Until then, the Send button stays off.
319
+ - **In an app with `basePath`** in `next.config.ts`, include that prefix in `embedPath`.
320
+
219
321
  ## Staging and production
220
322
 
221
323
  Each environment usually embeds the chat on different sites. Read the list from an environment variable, for example `ASKDARE_ALLOWED_ORIGINS`, split on commas:
package/docs/events.md CHANGED
@@ -73,7 +73,7 @@ Every event has `type` and `bot`, the bot's ID. The other fields depend on the t
73
73
  | `length` | number | The message's length in characters. |
74
74
  | `attachments` | number | How many images and PDFs it carried. |
75
75
  | `source` | `'typed'`, `'starter'` or `'reply'` | Typed or dictated into the field, picked from the suggested questions before the conversation, or picked from the [options](reply-options.md) under the latest answer. |
76
- | `outcome` | `'completed'`, `'failed'` or `'stopped'` | `stopped` when the chat was taken down mid-answer, as when a React `Root` unmounts or the chat reloads in another language. |
76
+ | `outcome` | `'completed'`, `'failed'` or `'stopped'` | `stopped` when the chat was taken down mid-answer, as when a React `Root` unmounts or the chat has to reload in another language. |
77
77
  | `durationMs` | number | From sending the message to the end of the answer. |
78
78
  | `citations` | number | How many sources the answer cites. |
79
79
  | `rating` | `'up'`, `'down'` or `null` | `null` when the visitor took their rating back. |
package/docs/privacy.md CHANGED
@@ -112,7 +112,7 @@ Everything below lives in the OpenAI project whose key the app uses. Name OpenAI
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. [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.
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. [Tool cards](react.md#tool-cards) work the same way: what a tool's `ui` picks from its result is sent to the visitor's browser and shown, and is derived again from the stored result after a reload, so pick only what the visitor may see. 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)).