@boldare/askdare 0.3.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/react.d.ts CHANGED
@@ -1,76 +1,14 @@
1
1
 
2
+ import { a as ToolResults, c as ChatConfig, f as PresetName, i as ToolRenderers, l as ChatStyles, n as LinkProps, o as ToolResultsProps, p as ThemeVariants, r as ToolRendererProps, s as ChatAttachments, t as Link, u as ChatWidget } from "./tool-results.js";
2
3
  import { ComponentProps, ComponentType, NamedExoticComponent, ReactElement, ReactNode, Ref } 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;
4
+ /** One tool call's payload, as the `tool.ui` event and the history carry it. */
5
+ interface ToolUi {
6
+ /** The call, as in `tool.status`. Opaque. */
7
+ readonly callId: string;
8
+ /** The tool's name, which picks the renderer. */
9
+ readonly name: string;
10
+ /** Whatever the tool's `ui` returned: plain JSON, never `null`. */
11
+ readonly data: unknown;
74
12
  }
75
13
  /** Parts of the default look you can replace. They take no props: read the chat with the hooks. */
76
14
  interface DefaultChatComponents {
@@ -82,9 +20,12 @@ interface DefaultChatComponents {
82
20
  readonly Footer?: ComponentType;
83
21
  }
84
22
  interface DefaultPanelProps {
85
- /** Level of the chat's title (default 2); 1 makes the chat the page's main landmark. */
23
+ /**
24
+ * Level of the chat's title (default 2, or 1 inside `EmbedRoot`); 1 makes the chat the page's
25
+ * main landmark.
26
+ */
86
27
  readonly headingLevel?: 1 | 2 | 3 | 4 | 5;
87
- /** Shows a close button, and Escape calls it too. */
28
+ /** Shows a close button, and Escape calls it too. Inside `EmbedRoot`, it closes the widget by default. */
88
29
  readonly onClose?: (() => void) | undefined;
89
30
  readonly components?: DefaultChatComponents | undefined;
90
31
  }
@@ -156,6 +97,11 @@ interface ChatMessage {
156
97
  * is the latest message; a click sends the option as the visitor's own message.
157
98
  */
158
99
  readonly replies?: readonly string[] | undefined;
100
+ /**
101
+ * What the turn's tools picked from their results for the visitor to see (ADR-0017), in call
102
+ * order, at most four: plain JSON for the components registered with `toolRenderers`.
103
+ */
104
+ readonly ui?: readonly ToolUi[] | undefined;
159
105
  }
160
106
  type Rating = "up" | "down";
161
107
  /** A file picked for the next message. */
@@ -417,6 +363,19 @@ interface Chat {
417
363
  /** A text in the visitor's language by its key, such as `composer.send`. */
418
364
  readonly t: Translate;
419
365
  }
366
+ /**
367
+ * The chat is the whole document of the widget's iframe (`EmbedRoot`, ADR-0018): `close` asks the
368
+ * loader to close the panel; undefined when the page isn't in an iframe or in `inline` mode.
369
+ */
370
+ interface Frame {
371
+ readonly close: (() => void) | undefined;
372
+ }
373
+ /**
374
+ * Inside `EmbedRoot`, on your own page in the widget's iframe (ADR-0018): the chat is the whole
375
+ * document, and `close` asks the loader to close the panel (undefined in `inline` mode or when the
376
+ * page isn't in the widget). Null everywhere else. Your own markup uses it for a close button.
377
+ */
378
+ export declare function useFrame(): Frame | null;
420
379
  /** The whole chat: its state, actions, bot settings and texts. Re-renders on every change. */
421
380
  export declare function useChat(): Chat;
422
381
  /**
@@ -527,11 +486,18 @@ interface RootProps {
527
486
  * rating (ADR-0013). Metadata only, never the text. A new function doesn't restart the chat.
528
487
  */
529
488
  readonly onEvent?: ChatEventListener | undefined;
489
+ /**
490
+ * Your components for tools' results, by tool name (ADR-0017): each gets what the tool's `ui`
491
+ * returned and is drawn by `ToolResults`, in `DefaultChat` under the answer. Type them with
492
+ * `satisfies ToolRenderers<[typeof myTool]>`. Define the map outside your component (or
493
+ * memoize it): a new object on every render re-renders every card.
494
+ */
495
+ readonly toolRenderers?: ToolRenderers | undefined;
530
496
  readonly children?: ReactNode;
531
497
  }
532
498
  /**
533
499
  * Runs one bot's chat for the components inside it, without rendering any element. Its props
534
500
  * take what `askdare('identify')` and `askdare('configure')` take, checked the same way.
535
501
  */
536
- export declare function Root({ config, identity, context, greeting, starters, onEvent, children }: RootProps): ReactElement;
537
- export type { AttachButtonProps, Chat, ChatActions, ChatAttachments, ChatBot, ChatConfig, ChatEvent, ChatEventListener, ChatEventType, ChatMessage, ChatPhase, ChatState, ChatStyles, ChatWidget, Citation, CitationsProps, ComposerProps, DefaultChatComponents, DefaultChatProps, DictateButtonProps, Dictation, ErrorMessageProps, FeedbackButtonProps, FilesProps, InputProps, MarkdownProps, MessageFilesProps, MessageListProps, MessageProps, MessageTextProps, MessagesProps, PanelProps, PendingFile, QuickRepliesProps, Rating, RecorderProps, RootProps, SendProps, SentFile, StatusProps, ThemeProps, Translate };
502
+ export declare function Root({ config, identity, context, greeting, starters, onEvent, toolRenderers, children }: RootProps): ReactElement;
503
+ export { type AttachButtonProps, type Chat, type ChatActions, type ChatAttachments, type ChatBot, type ChatConfig, type ChatEvent, type ChatEventListener, type ChatEventType, type ChatMessage, type ChatPhase, type ChatState, type ChatStyles, type ChatWidget, type Citation, type CitationsProps, type ComposerProps, type DefaultChatComponents, type DefaultChatProps, type DictateButtonProps, type Dictation, type ErrorMessageProps, type FeedbackButtonProps, type FilesProps, type Frame, type InputProps, Link, type LinkProps, type MarkdownProps, type MessageFilesProps, type MessageListProps, type MessageProps, type MessageTextProps, type MessagesProps, type PanelProps, type PendingFile, type QuickRepliesProps, type Rating, type RecorderProps, type RootProps, type SendProps, type SentFile, type StatusProps, type ThemeProps, type ToolRendererProps, type ToolRenderers, ToolResults, type ToolResultsProps, type ToolUi, type Translate };