@boldare/askdare 0.2.0 → 0.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/{version.js → define-tool.js} +162 -15
- package/dist/index.js +4 -33
- package/dist/next.js +317 -179
- package/dist/react.d.ts +28 -4
- package/dist/react.js +124 -36
- package/dist/store.d.ts +31 -3
- package/dist/ui/askdare.css +67 -1
- package/dist/ui/avatar.tsx +1 -1
- package/dist/ui/chat.tsx +1 -1
- package/dist/ui/confirm.tsx +1 -1
- package/dist/ui/context.ts +1 -1
- package/dist/ui/feedback.tsx +1 -1
- package/dist/ui/footer.tsx +7 -2
- package/dist/ui/header.tsx +1 -1
- package/dist/ui/icons.tsx +1 -1
- package/dist/ui/index.ts +1 -1
- package/dist/ui/message.tsx +17 -3
- package/dist/ui/panel.tsx +1 -1
- package/dist/ui/welcome.tsx +1 -1
- package/docs/configuration.md +1 -0
- package/docs/costs.md +9 -0
- package/docs/embedding.md +4 -3
- package/docs/events.md +2 -2
- package/docs/feedback.md +116 -0
- package/docs/privacy.md +3 -3
- package/docs/protocol.md +13 -1
- package/docs/react.md +5 -2
- package/docs/reply-options.md +240 -0
- package/docs/styling.md +6 -3
- package/docs/texts.md +97 -0
- package/docs/themes.md +2 -1
- package/docs/tools.md +24 -0
- package/llms.txt +3 -1
- package/package.json +1 -1
- package/skills/askdare/SKILL.md +4 -1
package/dist/react.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface ThemeVariants {
|
|
|
11
11
|
readonly surface: "solid" | "glass";
|
|
12
12
|
readonly density: "comfortable" | "compact";
|
|
13
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";
|
|
14
16
|
}
|
|
15
17
|
/** What a visitor may attach, as the bot allows it. */
|
|
16
18
|
interface ChatAttachments {
|
|
@@ -116,7 +118,11 @@ interface FeedbackHandle {
|
|
|
116
118
|
/** Stable for the answer across reloads, so the client can remember its rating. Hex. */
|
|
117
119
|
readonly key: string;
|
|
118
120
|
}
|
|
119
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* What a page may set with askdare('configure') or the props of `Root`, checked again here. The
|
|
123
|
+
* language isn't among them: it comes with the chat's address (`?lang=`, or `getChatConfig` in
|
|
124
|
+
* React), so switching it reloads the chat (ADR-0014).
|
|
125
|
+
*/
|
|
120
126
|
interface PageOptions {
|
|
121
127
|
readonly greeting?: string;
|
|
122
128
|
readonly starters?: readonly string[];
|
|
@@ -145,6 +151,11 @@ interface ChatMessage {
|
|
|
145
151
|
readonly status: "streaming" | "done" | "error";
|
|
146
152
|
/** On answers the visitor may rate: `key` is where `ChatState.ratings` keeps their rating. */
|
|
147
153
|
readonly feedback?: FeedbackHandle | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Options the visitor can click instead of typing (ADR-0015); plain text. Shown only while this
|
|
156
|
+
* is the latest message; a click sends the option as the visitor's own message.
|
|
157
|
+
*/
|
|
158
|
+
readonly replies?: readonly string[] | undefined;
|
|
148
159
|
}
|
|
149
160
|
type Rating = "up" | "down";
|
|
150
161
|
/** A file picked for the next message. */
|
|
@@ -198,7 +209,7 @@ type ChatEvent = {
|
|
|
198
209
|
readonly bot: string;
|
|
199
210
|
readonly length: number;
|
|
200
211
|
readonly attachments: number;
|
|
201
|
-
readonly source: "typed" | "starter";
|
|
212
|
+
readonly source: "typed" | "starter" | "reply";
|
|
202
213
|
} | {
|
|
203
214
|
readonly type: "message.received";
|
|
204
215
|
readonly bot: string;
|
|
@@ -245,6 +256,7 @@ declare const EN: {
|
|
|
245
256
|
readonly "status.tool": "Using {name}…";
|
|
246
257
|
readonly "status.typing": "The assistant is typing";
|
|
247
258
|
readonly "message.sources": "Sources";
|
|
259
|
+
readonly "message.replies": "Suggested replies";
|
|
248
260
|
readonly "feedback.label": "Rate this answer";
|
|
249
261
|
readonly "feedback.up": "Helpful";
|
|
250
262
|
readonly "feedback.down": "Not helpful";
|
|
@@ -315,7 +327,10 @@ type TextKey = keyof typeof EN | `${(typeof PLURAL_BASES)[number]}.${(typeof PLU
|
|
|
315
327
|
type Translate = (key: TextKey, params?: Readonly<Record<string, string | number>>) => string;
|
|
316
328
|
/** What visitors can do in the chat; the same for every UI on top of the store. */
|
|
317
329
|
interface ChatActions {
|
|
318
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* Sends the draft with the files that are ready, or `text` (a starter, or one of the latest
|
|
332
|
+
* answer's `replies`) on its own.
|
|
333
|
+
*/
|
|
319
334
|
send(text?: string): Promise<void>;
|
|
320
335
|
setDraft(text: string): void;
|
|
321
336
|
/** Uploads files for the next message, as many as the bot allows. */
|
|
@@ -484,6 +499,15 @@ interface PanelProps extends ComponentProps<"section"> {
|
|
|
484
499
|
* on it are attached (`data-dragging` while they are over it).
|
|
485
500
|
*/
|
|
486
501
|
export declare function Panel({ landmark, onDragOver, onDragLeave, onDrop, ...props }: PanelProps): ReactElement;
|
|
502
|
+
type QuickRepliesProps = ComponentProps<"div">;
|
|
503
|
+
/**
|
|
504
|
+
* The options the latest answer offers (ADR-0015): a group (`replies`) of buttons (`reply`), each
|
|
505
|
+
* showing its option as plain text, never Markdown. A click sends the option as the visitor's own
|
|
506
|
+
* message, exactly as if they had typed it. Inside `MessageList` it renders under the latest
|
|
507
|
+
* answer only; anywhere else, such as above the message field, it shows the latest answer's
|
|
508
|
+
* options. Either way the options go away as soon as the visitor sends anything.
|
|
509
|
+
*/
|
|
510
|
+
export declare function QuickReplies(props: QuickRepliesProps): ReactElement | null;
|
|
487
511
|
interface RootProps {
|
|
488
512
|
/** From `getChatConfig()` in a Server Component. */
|
|
489
513
|
readonly config: ChatConfig;
|
|
@@ -510,4 +534,4 @@ interface RootProps {
|
|
|
510
534
|
* take what `askdare('identify')` and `askdare('configure')` take, checked the same way.
|
|
511
535
|
*/
|
|
512
536
|
export declare function Root({ config, identity, context, greeting, starters, onEvent, children }: RootProps): ReactElement;
|
|
513
|
-
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, Rating, RecorderProps, RootProps, SendProps, SentFile, StatusProps, ThemeProps, Translate };
|
|
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 };
|
package/dist/react.js
CHANGED
|
@@ -66,6 +66,10 @@ function MessageProvider({ message, children }) {
|
|
|
66
66
|
children
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
/** The message being rendered, or null outside `MessageList`. */
|
|
70
|
+
function useOptionalMessage() {
|
|
71
|
+
return useContext(MessageContext);
|
|
72
|
+
}
|
|
69
73
|
/** The message being rendered, inside `MessageList`. */
|
|
70
74
|
function useMessage() {
|
|
71
75
|
const message = useContext(MessageContext);
|
|
@@ -345,8 +349,8 @@ function focusElement(ref, explicit = false) {
|
|
|
345
349
|
return true;
|
|
346
350
|
}
|
|
347
351
|
// src/react/messages.tsx
|
|
348
|
-
/** False for an answer that ended (or failed) before any text,
|
|
349
|
-
const hasContent = (message) => message.role === "user" || message.status === "streaming" || message.text !== "" || message.citations.length > 0;
|
|
352
|
+
/** False for an answer that ended (or failed) before any text or sources, or options to show. */
|
|
353
|
+
const hasContent = (message) => message.role === "user" || message.status === "streaming" || message.text !== "" || message.citations.length > 0 || message.status === "done" && (message.replies?.length ?? 0) > 0;
|
|
350
354
|
/**
|
|
351
355
|
* The conversation: a live region that follows the latest message as it streams. Holds the
|
|
352
356
|
* welcome, the `MessageList` and the `Status`.
|
|
@@ -804,6 +808,38 @@ function Panel({ landmark = "region", onDragOver, onDragLeave, onDrop, ...props
|
|
|
804
808
|
...props
|
|
805
809
|
});
|
|
806
810
|
}
|
|
811
|
+
// src/react/replies.tsx
|
|
812
|
+
/**
|
|
813
|
+
* The options the latest answer offers (ADR-0015): a group (`replies`) of buttons (`reply`), each
|
|
814
|
+
* showing its option as plain text, never Markdown. A click sends the option as the visitor's own
|
|
815
|
+
* message, exactly as if they had typed it. Inside `MessageList` it renders under the latest
|
|
816
|
+
* answer only; anywhere else, such as above the message field, it shows the latest answer's
|
|
817
|
+
* options. Either way the options go away as soon as the visitor sends anything.
|
|
818
|
+
*/
|
|
819
|
+
function QuickReplies(props) {
|
|
820
|
+
const own = useOptionalMessage();
|
|
821
|
+
const { actions, t } = useStore();
|
|
822
|
+
const replies = useChatState((state) => {
|
|
823
|
+
const latest = state.messages.at(-1);
|
|
824
|
+
if (latest?.role !== "assistant" || latest.status !== "done") return void 0;
|
|
825
|
+
return own && own.id !== latest.id ? void 0 : latest.replies;
|
|
826
|
+
});
|
|
827
|
+
const disabled = useChatState((state) => state.busy || state.phase !== "ready");
|
|
828
|
+
if (!replies?.length) return null;
|
|
829
|
+
return /* @__PURE__ */ jsx("div", {
|
|
830
|
+
"data-ask-part": "replies",
|
|
831
|
+
role: "group",
|
|
832
|
+
"aria-label": t("message.replies"),
|
|
833
|
+
...props,
|
|
834
|
+
children: replies.map((reply, index) => /* @__PURE__ */ jsx("button", {
|
|
835
|
+
type: "button",
|
|
836
|
+
"data-ask-part": "reply",
|
|
837
|
+
disabled,
|
|
838
|
+
onClick: () => void actions.send(reply),
|
|
839
|
+
children: reply
|
|
840
|
+
}, index))
|
|
841
|
+
});
|
|
842
|
+
}
|
|
807
843
|
// src/base-path.ts
|
|
808
844
|
/**
|
|
809
845
|
* Whether a chat route's `basePath` is a path on the app itself, like `/api/chat`: never another
|
|
@@ -869,9 +905,32 @@ const PROTOCOL_EVENT_TYPES = [
|
|
|
869
905
|
"text.delta",
|
|
870
906
|
"citation",
|
|
871
907
|
"tool.status",
|
|
908
|
+
"replies",
|
|
872
909
|
"message.end",
|
|
873
910
|
"error"
|
|
874
911
|
];
|
|
912
|
+
/**
|
|
913
|
+
* A URL or something a browser or a chat app would turn into a link: a scheme (`https://`,
|
|
914
|
+
* `mailto:`, `javascript:` …), `www.`, an IP address or a domain name such as `example.com`.
|
|
915
|
+
* Strict on purpose: a few odd names (`Node.js`) are dropped with them.
|
|
916
|
+
*/
|
|
917
|
+
const LINK = /[a-z][a-z\d+.-]*:\/\/|\b(?:mailto|tel|sms|javascript|vbscript|data|file):|\bwww\.|\b\d{1,3}(?:\.\d{1,3}){3}\b|[\p{L}\d-]\.[a-z]{2,}(?![\p{L}\d])/iu;
|
|
918
|
+
/**
|
|
919
|
+
* Characters the visitor can't see or read: line breaks and other control characters, format
|
|
920
|
+
* characters (bidirectional overrides that reorder text, zero-width characters, tag characters
|
|
921
|
+
* that can spell hidden words), private-use and unassigned code points. A click sends the option
|
|
922
|
+
* as the visitor's own message, so it must say exactly what they read. The zero-width joiner stays
|
|
923
|
+
* for emoji built from several, such as "woman technologist".
|
|
924
|
+
*/
|
|
925
|
+
const CONTROL = /[\p{Cc}\p{Co}\p{Cn}\u2028\u2029]|(?!\u200d)\p{Cf}/u;
|
|
926
|
+
/** One option as it goes over the wire: trimmed, 1 to 80 characters, one line, no links. */
|
|
927
|
+
function isReplyText(value) {
|
|
928
|
+
return typeof value === "string" && value.length > 0 && value.length <= 80 && value === value.trim() && !CONTROL.test(value) && !LINK.test(value);
|
|
929
|
+
}
|
|
930
|
+
/** A list of options as it goes over the wire: 1 to 4 valid options, no duplicates. */
|
|
931
|
+
function isReplyList(value) {
|
|
932
|
+
return Array.isArray(value) && value.length > 0 && value.length <= 4 && value.every(isReplyText) && new Set(value).size === value.length;
|
|
933
|
+
}
|
|
875
934
|
// src/protocol/validate.ts
|
|
876
935
|
const record$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
877
936
|
const text = (value, min = 0, max = Number.POSITIVE_INFINITY) => typeof value === "string" && value.length >= min && value.length <= max;
|
|
@@ -956,6 +1015,11 @@ function parseEvent(value) {
|
|
|
956
1015
|
name: value["name"],
|
|
957
1016
|
state: value["state"]
|
|
958
1017
|
} : void 0;
|
|
1018
|
+
case "replies": return messageId(id) && isReplyList(value["items"]) ? {
|
|
1019
|
+
type: "replies",
|
|
1020
|
+
messageId: id,
|
|
1021
|
+
items: [...value["items"]]
|
|
1022
|
+
} : void 0;
|
|
959
1023
|
case "message.end": {
|
|
960
1024
|
const { resumeToken } = value;
|
|
961
1025
|
if (!messageId(id) || !oneOf(value["reason"], MESSAGE_END_REASONS)) return;
|
|
@@ -995,13 +1059,16 @@ function historyMessageOf(value) {
|
|
|
995
1059
|
if (citations.some((citation) => citation === void 0)) return void 0;
|
|
996
1060
|
const feedback = value["feedback"] === void 0 ? void 0 : feedbackOf(value["feedback"]);
|
|
997
1061
|
if (value["feedback"] !== void 0 && !feedback) return void 0;
|
|
1062
|
+
const { replies } = value;
|
|
1063
|
+
if (replies !== void 0 && !isReplyList(replies)) return void 0;
|
|
998
1064
|
return {
|
|
999
1065
|
id: value["id"],
|
|
1000
1066
|
role: value["role"],
|
|
1001
1067
|
text: value["text"],
|
|
1002
1068
|
citations,
|
|
1003
1069
|
attachments: value["attachments"],
|
|
1004
|
-
...feedback ? { feedback } : {}
|
|
1070
|
+
...feedback ? { feedback } : {},
|
|
1071
|
+
...replies === void 0 ? {} : { replies: [...replies] }
|
|
1005
1072
|
};
|
|
1006
1073
|
}
|
|
1007
1074
|
/** The answer of `POST /history`, or undefined when it breaks the protocol. */
|
|
@@ -1628,7 +1695,8 @@ const fromHistory = (message) => ({
|
|
|
1628
1695
|
citations: message.citations,
|
|
1629
1696
|
attachments: message.attachments,
|
|
1630
1697
|
status: "done",
|
|
1631
|
-
...message.feedback ? { feedback: message.feedback } : {}
|
|
1698
|
+
...message.feedback ? { feedback: message.feedback } : {},
|
|
1699
|
+
...message.replies ? { replies: message.replies } : {}
|
|
1632
1700
|
});
|
|
1633
1701
|
/** The messages after one protocol event of a streamed answer. */
|
|
1634
1702
|
function applyEvent(messages, event) {
|
|
@@ -1654,6 +1722,10 @@ function applyEvent(messages, event) {
|
|
|
1654
1722
|
url: event.url
|
|
1655
1723
|
}]
|
|
1656
1724
|
}));
|
|
1725
|
+
case "replies": return update(event.messageId, (message) => ({
|
|
1726
|
+
...message,
|
|
1727
|
+
replies: event.items
|
|
1728
|
+
}));
|
|
1657
1729
|
case "message.end": return update(event.messageId, (message) => ({
|
|
1658
1730
|
...message,
|
|
1659
1731
|
status: "done",
|
|
@@ -1920,19 +1992,22 @@ function createChatStore(config, options = {}) {
|
|
|
1920
1992
|
const actions = {
|
|
1921
1993
|
async send(picked) {
|
|
1922
1994
|
const text = (picked ?? state.draft).trim();
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
const ready = state.files.filter((file) => file.status === "ready");
|
|
1995
|
+
if (picked === void 0 ? !canSend(state) : state.phase !== "ready" || state.busy || text === "") return;
|
|
1996
|
+
const ready = picked === void 0 ? state.files.filter((file) => file.status === "ready") : [];
|
|
1926
1997
|
const files = ready.flatMap(({ name, kind, previewUrl }) => kind ? [{
|
|
1927
1998
|
name,
|
|
1928
1999
|
kind,
|
|
1929
2000
|
previewUrl
|
|
1930
2001
|
}] : []);
|
|
1931
2002
|
const handles = ready.flatMap((file) => file.handle ? [file.handle] : []);
|
|
1932
|
-
|
|
2003
|
+
const latest = state.messages.at(-1);
|
|
2004
|
+
const source = picked === void 0 ? "typed" : latest?.role === "assistant" && latest.replies?.includes(text) ? "reply" : "starter";
|
|
2005
|
+
if (picked === void 0) revokePreviews(state.files.filter((file) => file.status !== "ready"));
|
|
1933
2006
|
set({
|
|
1934
|
-
|
|
1935
|
-
|
|
2007
|
+
...picked === void 0 ? {
|
|
2008
|
+
files: [],
|
|
2009
|
+
draft: ""
|
|
2010
|
+
} : {},
|
|
1936
2011
|
error: void 0,
|
|
1937
2012
|
busy: true,
|
|
1938
2013
|
messages: [...state.messages, {
|
|
@@ -1950,7 +2025,7 @@ function createChatStore(config, options = {}) {
|
|
|
1950
2025
|
bot,
|
|
1951
2026
|
length: [...text].length,
|
|
1952
2027
|
attachments: files.length,
|
|
1953
|
-
source
|
|
2028
|
+
source
|
|
1954
2029
|
});
|
|
1955
2030
|
const context = config.pageContext ? state.page.context : void 0;
|
|
1956
2031
|
const controller = new AbortController();
|
|
@@ -2437,30 +2512,37 @@ function useSkin() {
|
|
|
2437
2512
|
/** An h1–h6 tag name for a level, capped at 6. */
|
|
2438
2513
|
const heading = (level) => `h${Math.min(Math.max(level, 1), 6)}`;
|
|
2439
2514
|
// src/react/skin/footer.tsx
|
|
2440
|
-
/**
|
|
2515
|
+
/**
|
|
2516
|
+
* The latest answer's options when the theme puts them here, the message field with its buttons
|
|
2517
|
+
* (or the dictation in its place), then the AI notice.
|
|
2518
|
+
*/
|
|
2441
2519
|
function DefaultFooter() {
|
|
2442
2520
|
const { state, bot, t } = useChat();
|
|
2443
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2444
|
-
"data-
|
|
2445
|
-
children:
|
|
2446
|
-
|
|
2447
|
-
/* @__PURE__ */
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2521
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2522
|
+
bot.variants.replies === "composer" && /* @__PURE__ */ jsx(QuickReplies, { "data-placement": "composer" }),
|
|
2523
|
+
/* @__PURE__ */ jsxs(Composer, { children: [/* @__PURE__ */ jsx(Files, {}), /* @__PURE__ */ jsx("div", {
|
|
2524
|
+
"data-ask-part": "composer-box",
|
|
2525
|
+
children: state.dictation === "idle" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2526
|
+
/* @__PURE__ */ jsx(AttachButton, { children: /* @__PURE__ */ jsx(AttachIcon, {}) }),
|
|
2527
|
+
/* @__PURE__ */ jsx(Input, {}),
|
|
2528
|
+
/* @__PURE__ */ jsx(DictateButton, { children: /* @__PURE__ */ jsx(MicIcon, {}) }),
|
|
2529
|
+
/* @__PURE__ */ jsxs(Send, { children: [/* @__PURE__ */ jsx(SendIcon, {}), /* @__PURE__ */ jsx("span", {
|
|
2530
|
+
"data-ask-part": "send-label",
|
|
2531
|
+
"aria-hidden": "true",
|
|
2532
|
+
children: t("composer.send")
|
|
2533
|
+
})] })
|
|
2534
|
+
] }) : /* @__PURE__ */ jsx(Recorder, { cancelIcon: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
2535
|
+
})] }),
|
|
2536
|
+
bot.disclosure !== false && /* @__PURE__ */ jsxs("p", {
|
|
2537
|
+
"data-ask-part": "disclosure",
|
|
2538
|
+
children: [t("disclosure.text"), bot.disclosure.privacyUrl && /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("a", {
|
|
2539
|
+
href: bot.disclosure.privacyUrl,
|
|
2540
|
+
target: "_blank",
|
|
2541
|
+
rel: "noopener noreferrer",
|
|
2542
|
+
children: t("disclosure.privacy")
|
|
2543
|
+
})] })]
|
|
2544
|
+
})
|
|
2545
|
+
] });
|
|
2464
2546
|
}
|
|
2465
2547
|
// src/react/skin/avatar.tsx
|
|
2466
2548
|
const initials = (title) => title.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0]?.toUpperCase() ?? "").join("") || "AI";
|
|
@@ -2603,16 +2685,22 @@ function Feedback() {
|
|
|
2603
2685
|
}), commenting && /* @__PURE__ */ jsx(Comment, {})] });
|
|
2604
2686
|
}
|
|
2605
2687
|
// src/react/skin/message.tsx
|
|
2606
|
-
/**
|
|
2688
|
+
/**
|
|
2689
|
+
* One message: the assistant's face beside its answers, then text, files, sources, rating and,
|
|
2690
|
+
* under the latest answer, the options the visitor can click (unless the theme puts them above
|
|
2691
|
+
* the message field).
|
|
2692
|
+
*/
|
|
2607
2693
|
function DefaultMessage() {
|
|
2608
2694
|
const message = useMessage();
|
|
2695
|
+
const { variants } = useSkin().bot;
|
|
2609
2696
|
return /* @__PURE__ */ jsxs(Message, { children: [message.role === "assistant" && /* @__PURE__ */ jsx(Avatar, { size: "small" }), /* @__PURE__ */ jsxs("div", {
|
|
2610
2697
|
"data-ask-part": "message-body",
|
|
2611
2698
|
children: [
|
|
2612
2699
|
/* @__PURE__ */ jsx(MessageText, {}),
|
|
2613
2700
|
/* @__PURE__ */ jsx(MessageFiles, {}),
|
|
2614
2701
|
/* @__PURE__ */ jsx(Citations, {}),
|
|
2615
|
-
/* @__PURE__ */ jsx(Feedback, {})
|
|
2702
|
+
/* @__PURE__ */ jsx(Feedback, {}),
|
|
2703
|
+
variants.replies === "answer" && /* @__PURE__ */ jsx(QuickReplies, {})
|
|
2616
2704
|
]
|
|
2617
2705
|
})] });
|
|
2618
2706
|
}
|
|
@@ -2800,4 +2888,4 @@ function DefaultChat({ className, colorScheme, ...panel }) {
|
|
|
2800
2888
|
}), /* @__PURE__ */ jsx(DefaultPanel, { ...panel })]
|
|
2801
2889
|
});
|
|
2802
2890
|
}
|
|
2803
|
-
export { AttachButton, Citations, Composer, DefaultChat, DictateButton, ErrorMessage, FeedbackButton, Files, Input, Markdown, Message, MessageFiles, MessageList, MessageText, Messages, Panel, Recorder, Root, Send, Status, Theme, useChat, useChatState, useMessage };
|
|
2891
|
+
export { AttachButton, Citations, Composer, DefaultChat, DictateButton, ErrorMessage, FeedbackButton, Files, Input, Markdown, Message, MessageFiles, MessageList, MessageText, Messages, Panel, QuickReplies, Recorder, Root, Send, Status, Theme, useChat, useChatState, useMessage };
|
package/dist/store.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ declare const EN: {
|
|
|
24
24
|
readonly "status.tool": "Using {name}…";
|
|
25
25
|
readonly "status.typing": "The assistant is typing";
|
|
26
26
|
readonly "message.sources": "Sources";
|
|
27
|
+
readonly "message.replies": "Suggested replies";
|
|
27
28
|
readonly "feedback.label": "Rate this answer";
|
|
28
29
|
readonly "feedback.up": "Helpful";
|
|
29
30
|
readonly "feedback.down": "Not helpful";
|
|
@@ -142,6 +143,8 @@ interface ThemeVariants {
|
|
|
142
143
|
readonly surface: "solid" | "glass";
|
|
143
144
|
readonly density: "comfortable" | "compact";
|
|
144
145
|
readonly composer: "outline" | "gradient";
|
|
146
|
+
/** Where the latest answer's options show: under it, or in one row above the message field. */
|
|
147
|
+
readonly replies: "answer" | "composer";
|
|
145
148
|
}
|
|
146
149
|
type ColorScheme = "auto" | "light" | "dark";
|
|
147
150
|
/** A theme built on a preset. Create it with {@link defineTheme} to share it between bots. */
|
|
@@ -179,7 +182,14 @@ interface ToolContext {
|
|
|
179
182
|
/** Aborted when the visitor leaves, the turn deadline passes or the tool times out. */
|
|
180
183
|
readonly signal: AbortSignal;
|
|
181
184
|
}
|
|
182
|
-
|
|
185
|
+
/**
|
|
186
|
+
* A value as `JSON.parse(JSON.stringify(value))` returns it: `toJSON()` applied (a `Date` becomes
|
|
187
|
+
* a string), functions, symbols and `undefined` fields gone.
|
|
188
|
+
*/
|
|
189
|
+
type Jsonified<T> = T extends {
|
|
190
|
+
toJSON(): infer R;
|
|
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> {
|
|
183
193
|
/** Name the model calls, 1–64 letters, digits, `_` or `-`. */
|
|
184
194
|
readonly name: string;
|
|
185
195
|
/** Tells the model when and how to use the tool. */
|
|
@@ -190,9 +200,18 @@ interface ToolDefinition<Input extends z.ZodObject> {
|
|
|
190
200
|
*/
|
|
191
201
|
readonly input: Input;
|
|
192
202
|
/** Runs on the server with validated arguments. The result is sent back to the model as JSON. */
|
|
193
|
-
readonly execute: (input: z.infer<Input>, context: ToolContext) =>
|
|
203
|
+
readonly execute: (input: z.infer<Input>, context: ToolContext) => Output | PromiseLike<Output>;
|
|
194
204
|
/** Default 10 s. */
|
|
195
205
|
readonly timeoutMs?: number;
|
|
206
|
+
/**
|
|
207
|
+
* Options the visitor can click under the answer, derived from a successful result (ADR-0015).
|
|
208
|
+
* It gets the result as the model received it, parsed back from JSON (a `Date` is a string), so
|
|
209
|
+
* the options come back the same after a reload. A call that failed defines none. At most 4 of
|
|
210
|
+
* up to 80 characters are shown, plain text without links; the others are dropped. The visitor
|
|
211
|
+
* sends a clicked option as their own message. Only the latest answer shows options; when
|
|
212
|
+
* several calls of a turn define them, the last one wins.
|
|
213
|
+
*/
|
|
214
|
+
readonly replies?: (output: Jsonified<Output>) => readonly string[] | undefined;
|
|
196
215
|
}
|
|
197
216
|
interface Tool {
|
|
198
217
|
readonly name: string;
|
|
@@ -200,12 +219,13 @@ interface Tool {
|
|
|
200
219
|
readonly input: z.ZodObject;
|
|
201
220
|
readonly execute: (input: unknown, context: ToolContext) => unknown;
|
|
202
221
|
readonly timeoutMs: number;
|
|
222
|
+
readonly replies?: ((output: unknown) => readonly string[] | undefined) | undefined;
|
|
203
223
|
}
|
|
204
224
|
/**
|
|
205
225
|
* Declares a server-side function the model may call. Arguments are validated with the schema
|
|
206
226
|
* before `execute` runs; failures are reported to the model, never to the visitor.
|
|
207
227
|
*/
|
|
208
|
-
declare function defineTool<Input extends z.ZodObject>(definition: ToolDefinition<Input>): Tool;
|
|
228
|
+
declare function defineTool<Input extends z.ZodObject, Output = unknown>(definition: ToolDefinition<Input, Output>): Tool;
|
|
209
229
|
/** Per-request context available when building instructions. */
|
|
210
230
|
interface BotContext {
|
|
211
231
|
/** Validated BCP 47 tag chosen by the widget. */
|
|
@@ -321,6 +341,12 @@ interface WidgetConfig {
|
|
|
321
341
|
* `createChatHandler` has `onFeedback`; `false` hides them for this bot. Default `true`.
|
|
322
342
|
*/
|
|
323
343
|
readonly feedback?: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* `suggest`: the model may offer 2–4 replies under an answer, which visitors click instead of
|
|
346
|
+
* typing. It adds a built-in tool, `suggest_replies`, so every model call costs a little more
|
|
347
|
+
* input, and a turn sometimes takes one more call (docs/costs.md). Default `off`.
|
|
348
|
+
*/
|
|
349
|
+
readonly replies?: "suggest" | "off";
|
|
324
350
|
/** The assistant's picture: a path on your app such as `/avatar.png`, or a small data: image. */
|
|
325
351
|
readonly avatar?: string;
|
|
326
352
|
/** Text on the pill launcher; shortcut for `texts['launcher.label']`. */
|
|
@@ -342,6 +368,8 @@ interface BotWidget {
|
|
|
342
368
|
readonly starters: readonly string[];
|
|
343
369
|
/** Whether this bot lets visitors rate answers, when the handler has `onFeedback`. */
|
|
344
370
|
readonly feedback: boolean;
|
|
371
|
+
/** Whether the model suggests reply options. Only the server reads it. */
|
|
372
|
+
readonly replies: "suggest" | "off";
|
|
345
373
|
readonly avatar: string | undefined;
|
|
346
374
|
readonly launcherLabel: string;
|
|
347
375
|
/** Text overrides, including the title, greeting, placeholder and launcher label shortcuts. */
|
package/dist/ui/askdare.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Ejected from @boldare/askdare@0.
|
|
1
|
+
/* Ejected from @boldare/askdare@0.3.0-rc.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
|
|
@@ -667,6 +667,72 @@
|
|
|
667
667
|
cursor: default;
|
|
668
668
|
}
|
|
669
669
|
|
|
670
|
+
/* ---------- Reply options under the latest answer ---------- */
|
|
671
|
+
|
|
672
|
+
[data-ask-part="replies"]:where([data-ask-skin] *) {
|
|
673
|
+
display: flex;
|
|
674
|
+
flex-wrap: wrap;
|
|
675
|
+
gap: calc(var(--ask-space) * 0.75);
|
|
676
|
+
margin-top: calc(var(--ask-space) * 0.25);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
[data-ask-part="reply"]:where([data-ask-skin] *) {
|
|
680
|
+
max-width: 100%;
|
|
681
|
+
padding: calc(var(--ask-space) * 0.75) calc(var(--ask-space) * 1.5);
|
|
682
|
+
border: 1px solid color-mix(in srgb, var(--ask-color-accent) 45%, var(--ask-color-border));
|
|
683
|
+
border-radius: 999px;
|
|
684
|
+
background: var(--ask-color-background);
|
|
685
|
+
color: var(--ask-color-text);
|
|
686
|
+
font: inherit;
|
|
687
|
+
font-size: 0.88rem;
|
|
688
|
+
line-height: 1.3;
|
|
689
|
+
text-align: left;
|
|
690
|
+
overflow-wrap: anywhere;
|
|
691
|
+
cursor: pointer;
|
|
692
|
+
transition:
|
|
693
|
+
background-color 150ms var(--ask-ease),
|
|
694
|
+
border-color 150ms var(--ask-ease);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
[data-ask-part="reply"]:hover:not(:disabled):where([data-ask-skin] *) {
|
|
698
|
+
border-color: var(--ask-color-accent);
|
|
699
|
+
background: color-mix(in srgb, var(--ask-color-accent) 10%, var(--ask-color-background));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
[data-ask-part="reply"]:disabled:where([data-ask-skin] *) {
|
|
703
|
+
opacity: 0.55;
|
|
704
|
+
cursor: default;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/* Above the message field (variant replies: composer): one row that scrolls sideways. */
|
|
708
|
+
[data-ask-part="replies"][data-placement="composer"]:where([data-ask-skin] *) {
|
|
709
|
+
flex-wrap: nowrap;
|
|
710
|
+
margin: 0;
|
|
711
|
+
/* In line with the message field; the edges fade where options scroll out of view. */
|
|
712
|
+
padding: var(--ask-space) calc(var(--ask-space) * 1.5) 2px;
|
|
713
|
+
scroll-padding-inline: calc(var(--ask-space) * 1.5);
|
|
714
|
+
mask-image: linear-gradient(
|
|
715
|
+
to right,
|
|
716
|
+
transparent,
|
|
717
|
+
#000 calc(var(--ask-space) * 1.5),
|
|
718
|
+
#000 calc(100% - var(--ask-space) * 1.5),
|
|
719
|
+
transparent
|
|
720
|
+
);
|
|
721
|
+
overflow-x: auto;
|
|
722
|
+
scrollbar-width: none;
|
|
723
|
+
overscroll-behavior-x: contain;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
[data-ask-part="replies"][data-placement="composer"]::-webkit-scrollbar:where([data-ask-skin] *) {
|
|
727
|
+
display: none;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
[data-ask-part="replies"][data-placement="composer"]
|
|
731
|
+
[data-ask-part="reply"]:where([data-ask-skin] *) {
|
|
732
|
+
flex: none;
|
|
733
|
+
white-space: nowrap;
|
|
734
|
+
}
|
|
735
|
+
|
|
670
736
|
/* ---------- Welcome ---------- */
|
|
671
737
|
|
|
672
738
|
[data-ask-part="welcome"]:where([data-ask-skin] *) {
|
package/dist/ui/avatar.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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
|
package/dist/ui/confirm.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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';
|
package/dist/ui/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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
|
|
package/dist/ui/feedback.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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';
|
package/dist/ui/footer.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
|
|
2
2
|
import {
|
|
3
3
|
AttachButton,
|
|
4
4
|
Composer,
|
|
5
5
|
DictateButton,
|
|
6
6
|
Files,
|
|
7
7
|
Input,
|
|
8
|
+
QuickReplies,
|
|
8
9
|
Recorder,
|
|
9
10
|
Send,
|
|
10
11
|
useChat,
|
|
@@ -12,11 +13,15 @@ import {
|
|
|
12
13
|
import type { ReactElement } from 'react';
|
|
13
14
|
import { AttachIcon, CloseIcon, MicIcon, SendIcon } from './icons';
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The latest answer's options when the theme puts them here, the message field with its buttons
|
|
18
|
+
* (or the dictation in its place), then the AI notice.
|
|
19
|
+
*/
|
|
16
20
|
export function DefaultFooter(): ReactElement {
|
|
17
21
|
const { state, bot, t } = useChat();
|
|
18
22
|
return (
|
|
19
23
|
<>
|
|
24
|
+
{bot.variants.replies === 'composer' && <QuickReplies data-placement="composer" />}
|
|
20
25
|
<Composer>
|
|
21
26
|
<Files />
|
|
22
27
|
<div data-ask-part="composer-box">
|
package/dist/ui/header.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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.
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.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.
|
package/dist/ui/message.tsx
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
// Ejected from @boldare/askdare@0.
|
|
2
|
-
import {
|
|
1
|
+
// Ejected from @boldare/askdare@0.3.0-rc.0 with `npx @boldare/askdare add ui`. This copy is yours to change.
|
|
2
|
+
import {
|
|
3
|
+
Citations,
|
|
4
|
+
Message,
|
|
5
|
+
MessageFiles,
|
|
6
|
+
MessageText,
|
|
7
|
+
QuickReplies,
|
|
8
|
+
useMessage,
|
|
9
|
+
} from '@boldare/askdare/react';
|
|
3
10
|
import type { ReactElement } from 'react';
|
|
4
11
|
import { Avatar } from './avatar';
|
|
12
|
+
import { useSkin } from './context';
|
|
5
13
|
import { Feedback } from './feedback';
|
|
6
14
|
|
|
7
|
-
/**
|
|
15
|
+
/**
|
|
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).
|
|
19
|
+
*/
|
|
8
20
|
export function DefaultMessage(): ReactElement {
|
|
9
21
|
const message = useMessage();
|
|
22
|
+
const { variants } = useSkin().bot;
|
|
10
23
|
return (
|
|
11
24
|
<Message>
|
|
12
25
|
{message.role === 'assistant' && <Avatar size="small" />}
|
|
@@ -15,6 +28,7 @@ export function DefaultMessage(): ReactElement {
|
|
|
15
28
|
<MessageFiles />
|
|
16
29
|
<Citations />
|
|
17
30
|
<Feedback />
|
|
31
|
+
{variants.replies === 'answer' && <QuickReplies />}
|
|
18
32
|
</div>
|
|
19
33
|
</Message>
|
|
20
34
|
);
|