@bitbaum/chatkit 0.14.2 → 0.15.1
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/README.md +61 -0
- package/dist/chart.d.ts +115 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +203 -0
- package/dist/chart.js.map +1 -0
- package/dist/react/Markdown.d.ts +4 -1
- package/dist/react/Markdown.d.ts.map +1 -1
- package/dist/react/Markdown.js +8 -3
- package/dist/react/Markdown.js.map +1 -1
- package/dist/react/RichBlock.d.ts +15 -1
- package/dist/react/RichBlock.d.ts.map +1 -1
- package/dist/react/RichBlock.js +22 -1
- package/dist/react/RichBlock.js.map +1 -1
- package/dist/react/Screen.d.ts +9 -1
- package/dist/react/Screen.d.ts.map +1 -1
- package/dist/react/Screen.js +3 -2
- package/dist/react/Screen.js.map +1 -1
- package/dist/react/Thread.d.ts +11 -2
- package/dist/react/Thread.d.ts.map +1 -1
- package/dist/react/Thread.js +8 -5
- package/dist/react/Thread.js.map +1 -1
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/renderers.d.ts +20 -0
- package/dist/react/renderers.d.ts.map +1 -0
- package/dist/react/renderers.js +14 -0
- package/dist/react/renderers.js.map +1 -0
- package/dist/replies.d.ts +16 -0
- package/dist/replies.d.ts.map +1 -1
- package/dist/replies.js +92 -4
- package/dist/replies.js.map +1 -1
- package/dist/rich.d.ts +5 -1
- package/dist/rich.d.ts.map +1 -1
- package/dist/rich.js +19 -3
- package/dist/rich.js.map +1 -1
- package/package.json +1 -1
- package/styles.css +35 -0
package/dist/react/Screen.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
import { type RichRenderers } from "./renderers.js";
|
|
2
3
|
/**
|
|
3
4
|
* The chat as the whole screen, the way the ChatGPT and Claude apps lay it
|
|
4
5
|
* out: the conversation runs edge to edge and top to bottom, and the controls
|
|
@@ -17,7 +18,14 @@ import { type ReactNode } from "react";
|
|
|
17
18
|
*
|
|
18
19
|
* chatkit's own `ChatThread` does that already.
|
|
19
20
|
*/
|
|
20
|
-
export declare function ChatScreen({ header, composer, footnote, children, fill, className, }: {
|
|
21
|
+
export declare function ChatScreen({ header, composer, footnote, children, fill, className, renderers, }: {
|
|
22
|
+
/**
|
|
23
|
+
* The app's drawing for chart blocks in every answer on this screen:
|
|
24
|
+
* `{ chart: (block) => <Chart … /> }`. Reaches chatkit's thread and
|
|
25
|
+
* `Markdown` wherever they render under it; a `renderers` prop on one of
|
|
26
|
+
* them overrides it there.
|
|
27
|
+
*/
|
|
28
|
+
renderers?: RichRenderers;
|
|
21
29
|
/** Floats over the top of the conversation. Give its buttons `ck-glass`. */
|
|
22
30
|
header?: ReactNode;
|
|
23
31
|
/** The composer (and anything that belongs with it: an error, a queue). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Screen.d.ts","sourceRoot":"","sources":["../../src/react/Screen.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Screen.d.ts","sourceRoot":"","sources":["../../src/react/Screen.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,IAAe,EACf,SAAS,EACT,SAAS,GACV,EAAE;IACD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,2EAA2E;IAC3E,QAAQ,EAAE,SAAS,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,kEAAkE;IAClE,QAAQ,EAAE,SAAS,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,+BAmDA"}
|
package/dist/react/Screen.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useLayoutEffect, useRef } from "react";
|
|
4
4
|
import { useViewportHeight } from "./hooks.js";
|
|
5
|
+
import { RichRenderersContext } from "./renderers.js";
|
|
5
6
|
/**
|
|
6
7
|
* The chat as the whole screen, the way the ChatGPT and Claude apps lay it
|
|
7
8
|
* out: the conversation runs edge to edge and top to bottom, and the controls
|
|
@@ -20,7 +21,7 @@ import { useViewportHeight } from "./hooks.js";
|
|
|
20
21
|
*
|
|
21
22
|
* chatkit's own `ChatThread` does that already.
|
|
22
23
|
*/
|
|
23
|
-
export function ChatScreen({ header, composer, footnote, children, fill = "parent", className, }) {
|
|
24
|
+
export function ChatScreen({ header, composer, footnote, children, fill = "parent", className, renderers, }) {
|
|
24
25
|
const rootRef = useRef(null);
|
|
25
26
|
const headerRef = useRef(null);
|
|
26
27
|
const dockRef = useRef(null);
|
|
@@ -51,6 +52,6 @@ export function ChatScreen({ header, composer, footnote, children, fill = "paren
|
|
|
51
52
|
cls.push("ck-screen-viewport");
|
|
52
53
|
if (className)
|
|
53
54
|
cls.push(className);
|
|
54
|
-
return (_jsxs("div", { ref: rootRef, className: cls.join(" "), children: [_jsx("div", { className: "ck-screen-body", children: children }), hasHeader && (_jsx("div", { ref: headerRef, className: "ck-screen-header", children: _jsx("div", { className: "ck-screen-header-row", children: header }) })), _jsx("div", { ref: dockRef, className: "ck-screen-dock", children: _jsxs("div", { className: "ck-screen-column", children: [composer, footnote != null && _jsx("p", { className: "ck-screen-footnote", children: footnote })] }) })] }));
|
|
55
|
+
return (_jsxs("div", { ref: rootRef, className: cls.join(" "), children: [_jsx("div", { className: "ck-screen-body", children: renderers ? (_jsx(RichRenderersContext.Provider, { value: renderers, children: children })) : (children) }), hasHeader && (_jsx("div", { ref: headerRef, className: "ck-screen-header", children: _jsx("div", { className: "ck-screen-header-row", children: header }) })), _jsx("div", { ref: dockRef, className: "ck-screen-dock", children: _jsxs("div", { className: "ck-screen-column", children: [composer, footnote != null && _jsx("p", { className: "ck-screen-footnote", children: footnote })] }) })] }));
|
|
55
56
|
}
|
|
56
57
|
//# sourceMappingURL=Screen.js.map
|
package/dist/react/Screen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Screen.js","sourceRoot":"","sources":["../../src/react/Screen.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Screen.js","sourceRoot":"","sources":["../../src/react/Screen.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AAE1E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,IAAI,GAAG,QAAQ,EACf,SAAS,EACT,SAAS,GAwBV;IACC,MAAM,OAAO,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,MAAM,CAAwB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O,CACL,eAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,aACzC,cAAK,SAAS,EAAC,gBAAgB,YAC5B,SAAS,CAAC,CAAC,CAAC,CACX,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,YAC5C,QAAQ,GACqB,CACjC,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,GACG,EACL,SAAS,IAAI,CACZ,cAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAC,kBAAkB,YAC/C,cAAK,SAAS,EAAC,sBAAsB,YAAE,MAAM,GAAO,GAChD,CACP,EACD,cAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAC,gBAAgB,YAC3C,eAAK,SAAS,EAAC,kBAAkB,aAC9B,QAAQ,EACR,QAAQ,IAAI,IAAI,IAAI,YAAG,SAAS,EAAC,oBAAoB,YAAE,QAAQ,GAAK,IACjE,GACF,IACF,CACP,CAAC;AACJ,CAAC"}
|
package/dist/react/Thread.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type CitationMap, type RenderLink } from "./Markdown.js";
|
|
|
3
3
|
import type { Speaker } from "../speech.js";
|
|
4
4
|
import { type AnswerActionsLabels } from "./AnswerActions.js";
|
|
5
5
|
import type { AnswerFeedback } from "../review.js";
|
|
6
|
+
import type { RichRenderers } from "./renderers.js";
|
|
6
7
|
export type ChatSpeaker = {
|
|
7
8
|
/** Shown above the message when more than one agent can answer. */
|
|
8
9
|
name: string;
|
|
@@ -64,10 +65,12 @@ export declare const DEFAULT_THREAD_LABELS: ThreadLabels;
|
|
|
64
65
|
* no box, because it is the thing being READ. Copy is on every answer; Retry
|
|
65
66
|
* only on the last one (retrying an older turn would fork the thread).
|
|
66
67
|
*/
|
|
67
|
-
export declare function ChatMessage({ message, onRetry, renderLink, showSpeaker, footer, last, onReply, speaker, share, onFeedback, labels, }: {
|
|
68
|
+
export declare function ChatMessage({ message, onRetry, renderLink, showSpeaker, footer, last, onReply, speaker, share, onFeedback, renderers, labels, }: {
|
|
68
69
|
message: ChatMessageData;
|
|
69
70
|
/** Thumbs under the answer; the product keeps and exports what it learns. */
|
|
70
71
|
onFeedback?: (feedback: AnswerFeedback) => void;
|
|
72
|
+
/** The app's drawing for chart blocks (`{ chart }`); without it, a table. */
|
|
73
|
+
renderers?: RichRenderers;
|
|
71
74
|
/** The app's voice for Listen (the browser's without it). */
|
|
72
75
|
speaker?: Speaker | null;
|
|
73
76
|
/** What Share hands to the system sheet. `false` hides Share. */
|
|
@@ -120,10 +123,16 @@ export declare function ThinkingRow({ thinking, live, labels, }: {
|
|
|
120
123
|
* bottom, with a button back down once they are not; a turn in flight can be
|
|
121
124
|
* stopped from where it is being written.
|
|
122
125
|
*/
|
|
123
|
-
export declare function ChatThread({ messages, live, loading, stopped, onStop, onRetry, onReply, renderLink, renderFooter, showSpeakers, speaker, share, onFeedback, empty, children, labels: labelOverrides, }: {
|
|
126
|
+
export declare function ChatThread({ messages, live, loading, stopped, onStop, onRetry, onReply, renderLink, renderFooter, showSpeakers, speaker, share, onFeedback, renderers, empty, children, labels: labelOverrides, }: {
|
|
124
127
|
messages: ChatMessageData[];
|
|
125
128
|
/** Thumbs under every answer (chatkit's feedback loop, README). */
|
|
126
129
|
onFeedback?: (feedback: AnswerFeedback) => void;
|
|
130
|
+
/**
|
|
131
|
+
* The app's drawing for chart blocks: `{ chart: (block) => <Chart … /> }`.
|
|
132
|
+
* Without it (or when it returns null) chatkit shows the caption and a
|
|
133
|
+
* table of the data. `ChatScreen renderers` sets the same for every answer.
|
|
134
|
+
*/
|
|
135
|
+
renderers?: RichRenderers;
|
|
127
136
|
/** The app's voice for Listen under every answer (the browser's without it). */
|
|
128
137
|
speaker?: Speaker | null;
|
|
129
138
|
/** What Share hands to the system sheet. `false` hides Share. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Thread.d.ts","sourceRoot":"","sources":["../../src/react/Thread.tsx"],"names":[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CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;CAChC,+BA+FA;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,+BAiBA"}
|
package/dist/react/Thread.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { Markdown, defaultRenderLink } from "./Markdown.js";
|
|
4
4
|
import { useStickToBottom } from "./hooks.js";
|
|
5
|
-
import { extractReplies } from "../replies.js";
|
|
5
|
+
import { dropReplyLabel, extractReplies } from "../replies.js";
|
|
6
6
|
import { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS, } from "./AnswerActions.js";
|
|
7
7
|
import { IconArrowDown, IconChevron, IconRetry, IconStop } from "./icons.js";
|
|
8
8
|
/** "3m 38s", "42s", "1h 02m" — the ChatGPT app's unit words, so a product
|
|
@@ -34,12 +34,15 @@ export const DEFAULT_THREAD_LABELS = {
|
|
|
34
34
|
* no box, because it is the thing being READ. Copy is on every answer; Retry
|
|
35
35
|
* only on the last one (retrying an older turn would fork the thread).
|
|
36
36
|
*/
|
|
37
|
-
export function ChatMessage({ message, onRetry, renderLink = defaultRenderLink, showSpeaker = true, footer, last = false, onReply, speaker, share, onFeedback, labels = DEFAULT_THREAD_LABELS, }) {
|
|
37
|
+
export function ChatMessage({ message, onRetry, renderLink = defaultRenderLink, showSpeaker = true, footer, last = false, onReply, speaker, share, onFeedback, renderers, labels = DEFAULT_THREAD_LABELS, }) {
|
|
38
38
|
if (message.role === "user") {
|
|
39
39
|
return (_jsx("div", { className: "ck-turn ck-turn-user", children: _jsx("div", { className: "ck-bubble", children: message.content }) }));
|
|
40
40
|
}
|
|
41
41
|
const parsed = extractReplies(message.content);
|
|
42
42
|
const replies = message.replies ?? parsed.replies;
|
|
43
|
+
// Replies handed in by the app still get no heading drawn over them.
|
|
44
|
+
if (message.replies && message.replies.length > 0)
|
|
45
|
+
parsed.text = dropReplyLabel(parsed.text);
|
|
43
46
|
const cls = ["ck-turn", "ck-turn-answer"];
|
|
44
47
|
if (message.speaker?.id)
|
|
45
48
|
cls.push(`ck-from-${message.speaker.id}`);
|
|
@@ -48,7 +51,7 @@ export function ChatMessage({ message, onRetry, renderLink = defaultRenderLink,
|
|
|
48
51
|
// a phone must not stand between them.
|
|
49
52
|
if (last || message.failed)
|
|
50
53
|
cls.push("ck-turn-pinned");
|
|
51
|
-
return (_jsxs("div", { className: cls.join(" "), children: [showSpeaker && message.speaker && _jsx("span", { className: "ck-speaker", children: message.speaker.name }), message.thinking && _jsx(ThinkingRow, { thinking: message.thinking, labels: labels }), message.failed ? (_jsx("p", { className: "ck-failed", role: "status", children: message.content || labels.failed })) : (_jsx(Markdown, { text: parsed.text, citations: message.citations, renderLink: renderLink, onReply: last ? onReply : undefined })), footer, message.failed ? (onRetry && (_jsx("div", { className: "ck-turn-actions", children: _jsxs("button", { type: "button", className: "ck-action", onClick: onRetry, children: [_jsx(IconRetry, {}), _jsx("span", { children: labels.retry })] }) }))) : (_jsx(AnswerActions, { text: parsed.text, onRetry: onRetry, speaker: speaker, share: share, labels: labels, messageId: message.id, onFeedback: onFeedback })), last && onReply && !message.failed && replies.length > 0 && (_jsx(ChatReplies, { replies: replies, onPick: onReply, label: labels.replies }))] }));
|
|
54
|
+
return (_jsxs("div", { className: cls.join(" "), children: [showSpeaker && message.speaker && _jsx("span", { className: "ck-speaker", children: message.speaker.name }), message.thinking && _jsx(ThinkingRow, { thinking: message.thinking, labels: labels }), message.failed ? (_jsx("p", { className: "ck-failed", role: "status", children: message.content || labels.failed })) : (_jsx(Markdown, { text: parsed.text, citations: message.citations, renderLink: renderLink, onReply: last ? onReply : undefined, renderers: renderers })), footer, message.failed ? (onRetry && (_jsx("div", { className: "ck-turn-actions", children: _jsxs("button", { type: "button", className: "ck-action", onClick: onRetry, children: [_jsx(IconRetry, {}), _jsx("span", { children: labels.retry })] }) }))) : (_jsx(AnswerActions, { text: parsed.text, onRetry: onRetry, speaker: speaker, share: share, labels: labels, messageId: message.id, onFeedback: onFeedback })), last && onReply && !message.failed && replies.length > 0 && (_jsx(ChatReplies, { replies: replies, onPick: onReply, label: labels.replies }))] }));
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
54
57
|
* The replies under an answer. Exported for apps that render their own
|
|
@@ -84,7 +87,7 @@ export function ThinkingRow({ thinking, live = false, labels = DEFAULT_THREAD_LA
|
|
|
84
87
|
* bottom, with a button back down once they are not; a turn in flight can be
|
|
85
88
|
* stopped from where it is being written.
|
|
86
89
|
*/
|
|
87
|
-
export function ChatThread({ messages, live = null, loading = false, stopped = false, onStop, onRetry, onReply, renderLink = defaultRenderLink, renderFooter, showSpeakers, speaker, share, onFeedback, empty, children, labels: labelOverrides, }) {
|
|
90
|
+
export function ChatThread({ messages, live = null, loading = false, stopped = false, onStop, onRetry, onReply, renderLink = defaultRenderLink, renderFooter, showSpeakers, speaker, share, onFeedback, renderers, empty, children, labels: labelOverrides, }) {
|
|
88
91
|
const labels = { ...DEFAULT_THREAD_LABELS, ...labelOverrides };
|
|
89
92
|
const { scrollRef, endRef, following, onScroll, jumpToBottom } = useStickToBottom([messages.length, live?.text, live?.status, live?.steps?.length, stopped], messages.length);
|
|
90
93
|
if (loading) {
|
|
@@ -95,7 +98,7 @@ export function ChatThread({ messages, live = null, loading = false, stopped = f
|
|
|
95
98
|
const speakers = new Set([...messages.map((m) => m.speaker?.name), live?.speaker?.name].filter(Boolean));
|
|
96
99
|
const named = showSpeakers ?? speakers.size > 1;
|
|
97
100
|
const lastAnswer = [...messages].reverse().find((m) => m.role === "assistant");
|
|
98
|
-
return (_jsxs("div", { className: "ck-thread-wrap", children: [_jsx("div", { ref: scrollRef, className: "ck-thread", onScroll: onScroll, children: _jsxs("div", { className: "ck-thread-inner", children: [messages.map((m) => (_jsx(ChatMessage, { message: m, onRetry: onRetry && m.id === lastAnswer?.id && !live ? onRetry : undefined, renderLink: renderLink, showSpeaker: named, footer: renderFooter?.(m), last: m.id === lastAnswer?.id, onReply: live || stopped ? undefined : onReply, speaker: speaker, share: share, onFeedback: onFeedback, labels: labels }, m.id))), live && (_jsxs("div", { className: "ck-turn ck-turn-answer", children: [named && live.speaker && _jsx("span", { className: "ck-speaker", children: live.speaker.name }), live.steps && live.steps.length > 0 && (_jsx(ThinkingRow, { thinking: { steps: live.steps }, live: true, labels: labels })), live.text ? (_jsx(Markdown, { text: extractReplies(live.text).text, renderLink: renderLink })) : live.steps && live.steps.length > 0 ? null : (_jsxs("p", { className: "ck-live", role: "status", "aria-live": "polite", children: [_jsxs("span", { className: "ck-dots", "aria-hidden": true, children: [_jsx("span", {}), _jsx("span", {}), _jsx("span", {})] }), live.status ?? labels.working] })), onStop && (_jsxs("button", { type: "button", className: "ck-stop", onClick: onStop, children: [_jsx(IconStop, {}), labels.stop] }))] })), stopped && !live && (_jsx("p", { className: "ck-stopped", role: "status", children: labels.stopped })), children, _jsx("div", { ref: endRef })] }) }), !following && (_jsx("button", { type: "button", className: "ck-jump", onClick: jumpToBottom, "aria-label": labels.jump, title: labels.jump, children: _jsx(IconArrowDown, {}) }))] }));
|
|
101
|
+
return (_jsxs("div", { className: "ck-thread-wrap", children: [_jsx("div", { ref: scrollRef, className: "ck-thread", onScroll: onScroll, children: _jsxs("div", { className: "ck-thread-inner", children: [messages.map((m) => (_jsx(ChatMessage, { message: m, onRetry: onRetry && m.id === lastAnswer?.id && !live ? onRetry : undefined, renderLink: renderLink, showSpeaker: named, footer: renderFooter?.(m), last: m.id === lastAnswer?.id, onReply: live || stopped ? undefined : onReply, speaker: speaker, share: share, onFeedback: onFeedback, renderers: renderers, labels: labels }, m.id))), live && (_jsxs("div", { className: "ck-turn ck-turn-answer", children: [named && live.speaker && _jsx("span", { className: "ck-speaker", children: live.speaker.name }), live.steps && live.steps.length > 0 && (_jsx(ThinkingRow, { thinking: { steps: live.steps }, live: true, labels: labels })), live.text ? (_jsx(Markdown, { text: extractReplies(live.text, { streaming: true }).text, renderLink: renderLink, renderers: renderers })) : live.steps && live.steps.length > 0 ? null : (_jsxs("p", { className: "ck-live", role: "status", "aria-live": "polite", children: [_jsxs("span", { className: "ck-dots", "aria-hidden": true, children: [_jsx("span", {}), _jsx("span", {}), _jsx("span", {})] }), live.status ?? labels.working] })), onStop && (_jsxs("button", { type: "button", className: "ck-stop", onClick: onStop, children: [_jsx(IconStop, {}), labels.stop] }))] })), stopped && !live && (_jsx("p", { className: "ck-stopped", role: "status", children: labels.stopped })), children, _jsx("div", { ref: endRef })] }) }), !following && (_jsx("button", { type: "button", className: "ck-jump", onClick: jumpToBottom, "aria-label": labels.jump, title: labels.jump, children: _jsx(IconArrowDown, {}) }))] }));
|
|
99
102
|
}
|
|
100
103
|
/** The empty state that starts a conversation. It disappears once one has. */
|
|
101
104
|
export function ChatStarters({ starters, onPick, title, }) {
|
package/dist/react/Thread.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Thread.js","sourceRoot":"","sources":["../../src/react/Thread.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAqC,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/
|
|
1
|
+
{"version":3,"file":"Thread.js","sourceRoot":"","sources":["../../src/react/Thread.tsx"],"names":[],"mappings":"A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C,aAAa,KAAG,GACV,CACV,IACG,CACP,CAAC;AACJ,CAAC;AAID,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,KAAK,GAKN;IACC,OAAO,CACL,eAAK,SAAS,EAAC,aAAa,aACzB,KAAK,IAAI,cAAK,SAAS,EAAC,mBAAmB,YAAE,KAAK,GAAO,EAC1D,cAAK,SAAS,EAAC,kBAAkB,YAC9B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACrB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBAClD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;oBACjE,OAAO,CACL,iBAAgB,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,YAAY,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,YAC/E,KAAK,IADK,CAAC,CAEL,CACV,CAAC;gBACJ,CAAC,CAAC,GACE,IACF,CACP,CAAC;AACJ,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -26,5 +26,7 @@ export type { AttachMenuLabels } from "./AttachMenu.js";
|
|
|
26
26
|
export { useAttachments } from "./use-attachments.js";
|
|
27
27
|
export type { AttachmentsController } from "./use-attachments.js";
|
|
28
28
|
export { useClipboard, useStickToBottom, useViewportHeight, useAutoGrow } from "./hooks.js";
|
|
29
|
-
export { RichAnswerBlock } from "./RichBlock.js";
|
|
29
|
+
export { RichAnswerBlock, ChartTableFigure } from "./RichBlock.js";
|
|
30
|
+
export { RichRenderersContext, useRichRenderers } from "./renderers.js";
|
|
31
|
+
export type { RichRenderers } from "./renderers.js";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UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -18,5 +18,6 @@ export { useDictation } from "./use-dictation.js";
|
|
|
18
18
|
export { AttachMenu, DEFAULT_ATTACH_MENU_LABELS } from "./AttachMenu.js";
|
|
19
19
|
export { useAttachments } from "./use-attachments.js";
|
|
20
20
|
export { useClipboard, useStickToBottom, useViewportHeight, useAutoGrow } from "./hooks.js";
|
|
21
|
-
export { RichAnswerBlock } from "./RichBlock.js";
|
|
21
|
+
export { RichAnswerBlock, ChartTableFigure } from "./RichBlock.js";
|
|
22
|
+
export { RichRenderersContext, useRichRenderers } from "./renderers.js";
|
|
22
23
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OA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O,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ChartBlock } from "../chart.js";
|
|
3
|
+
/**
|
|
4
|
+
* The drawing an app injects into answers. chatkit stays dependency-free:
|
|
5
|
+
* it validates the data and leaves the slot; the app fills it.
|
|
6
|
+
*
|
|
7
|
+
* <ChatThread renderers={{ chart: (b) => <Chart {...b} /> }} … />
|
|
8
|
+
*
|
|
9
|
+
* A renderer that returns `null` hands the block back to chatkit's own
|
|
10
|
+
* fallback (the caption and a table of the data), so an app can draw the
|
|
11
|
+
* kinds it has a component for and leave the rest readable.
|
|
12
|
+
*/
|
|
13
|
+
export type RichRenderers = {
|
|
14
|
+
chart?: (block: ChartBlock) => ReactNode;
|
|
15
|
+
};
|
|
16
|
+
/** Set once at the screen (`ChatScreen renderers`), read by every answer in it. */
|
|
17
|
+
export declare const RichRenderersContext: import("react").Context<RichRenderers | undefined>;
|
|
18
|
+
/** The renderers in force: the prop, over what the screen provided. */
|
|
19
|
+
export declare function useRichRenderers(own?: RichRenderers): RichRenderers | undefined;
|
|
20
|
+
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/react/renderers.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,SAAS,CAAC;CAC1C,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,oBAAoB,oDAAsD,CAAC;AAExF,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAK/E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
/** Set once at the screen (`ChatScreen renderers`), read by every answer in it. */
|
|
4
|
+
export const RichRenderersContext = createContext(undefined);
|
|
5
|
+
/** The renderers in force: the prop, over what the screen provided. */
|
|
6
|
+
export function useRichRenderers(own) {
|
|
7
|
+
const inherited = useContext(RichRenderersContext);
|
|
8
|
+
if (!own)
|
|
9
|
+
return inherited;
|
|
10
|
+
if (!inherited)
|
|
11
|
+
return own;
|
|
12
|
+
return { ...inherited, ...own };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../src/react/renderers.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAiBlE,mFAAmF;AACnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAA4B,SAAS,CAAC,CAAC;AAExF,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,GAAmB;IAClD,MAAM,SAAS,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACnD,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,IAAI,CAAC,SAAS;QAAE,OAAO,GAAG,CAAC;IAC3B,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,GAAG,EAAE,CAAC;AAClC,CAAC"}
|
package/dist/replies.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ export type RepliesOptions = {
|
|
|
22
22
|
max?: number;
|
|
23
23
|
/** Longer than this is a sentence, not a button. Default 48. */
|
|
24
24
|
maxLength?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The text is a partial answer still arriving. A last line that could
|
|
27
|
+
* still turn into a label over the replies ("**Quick re…", "##", "---") is
|
|
28
|
+
* held back until the next line shows what it is, so a heading the model
|
|
29
|
+
* writes above its replies never flashes on screen.
|
|
30
|
+
*/
|
|
31
|
+
streaming?: boolean;
|
|
25
32
|
};
|
|
26
33
|
/**
|
|
27
34
|
* Append to a system prompt. The model leads: every answer ends with the two
|
|
@@ -32,6 +39,15 @@ export type RepliesOptions = {
|
|
|
32
39
|
* ends the conversation leaves the block off.
|
|
33
40
|
*/
|
|
34
41
|
export declare const REPLIES_INSTRUCTION: string;
|
|
42
|
+
/**
|
|
43
|
+
* Drop a heading, a bold or italic label, or a horizontal rule that sits
|
|
44
|
+
* directly above the replies. The reply buttons are their own label; a
|
|
45
|
+
* heading over them is the model narrating the interface, and in front of
|
|
46
|
+
* the buttons it reads as an empty section. Safe on any text: a real
|
|
47
|
+
* paragraph is never touched, and a label line that ends a paragraph
|
|
48
|
+
* (no blank line above it) belongs to that paragraph and stays.
|
|
49
|
+
*/
|
|
50
|
+
export declare function dropReplyLabel(text: string): string;
|
|
35
51
|
/**
|
|
36
52
|
* Split an answer into the text to show and its suggested replies. Safe on a
|
|
37
53
|
* partial, streaming answer: an unfinished block is hidden, never shown.
|
package/dist/replies.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replies.d.ts","sourceRoot":"","sources":["../src/replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IAC3B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"replies.d.ts","sourceRoot":"","sources":["../src/replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IAC3B,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,QAOpB,CAAC;AAmCb;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBnD;AAiDD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAiBrC"}
|
package/dist/replies.js
CHANGED
|
@@ -31,11 +31,94 @@ export const REPLIES_INSTRUCTION = [
|
|
|
31
31
|
"```" + REPLIES_FENCE,
|
|
32
32
|
'["Yes, do it", "Show me first", "Not now"]',
|
|
33
33
|
"```",
|
|
34
|
-
"Rules: write them in the person's language, in their voice (what THEY would say, not what you would). Each under 40 characters. Each must make sense sent on its own. Never repeat what they already said. Put the block last, after everything else. Leave it out only when the conversation is over (a goodbye, a thanks with nothing left to do).",
|
|
34
|
+
"Rules: write them in the person's language, in their voice (what THEY would say, not what you would). Each under 40 characters. Each must make sense sent on its own. Never repeat what they already said. Put the block last, after everything else. Do not write any heading or label before it (no Quick replies, Follow-up questions or the like, in any language): the replies are drawn as buttons. Leave it out only when the conversation is over (a goodbye, a thanks with nothing left to do).",
|
|
35
35
|
].join("\n");
|
|
36
36
|
const COMPLETE = new RegExp("\\n?```" + REPLIES_FENCE + "\\s*([\\s\\S]*?)```", "i");
|
|
37
37
|
// Still streaming: the fence has opened (or is opening) and not yet closed.
|
|
38
38
|
const OPEN_TAIL = new RegExp("\\n?```(?:" + REPLIES_FENCE + "[\\s\\S]*|q[a-z_]*)?$", "i");
|
|
39
|
+
// A label the model writes over its replies: "**Quick follow-up options**",
|
|
40
|
+
// "### Suggested replies", "_Mögliche Rückfragen:_", "Быстрые ответы:".
|
|
41
|
+
// Decided by SHAPE and POSITION, never by a word list, so it holds in every
|
|
42
|
+
// language: the last block before the replies, at most six words, and no
|
|
43
|
+
// sentence punctuation but a closing colon. A sentence — "**China holds
|
|
44
|
+
// 99 %.**", or anything longer — is part of the answer and stays.
|
|
45
|
+
const HEADING = /^#{1,6}\s+(.*?)(?:\s+#+)?$/;
|
|
46
|
+
const EMPHASIS = /^(\*\*\*|\*\*|\*|___|__|_)(?!\s)(.+?)(?<!\s)\1(:?)$/;
|
|
47
|
+
const RULE = /^(?:-{3,}|\*{3,}|_{3,})$/;
|
|
48
|
+
const MAX_LABEL_WORDS = 6;
|
|
49
|
+
function isLabelText(inner) {
|
|
50
|
+
const words = inner.replace(/[*_]+/g, "").replace(/:\s*$/, "").trim();
|
|
51
|
+
if (!words || /[.!?…;。!?]/.test(words) || words.includes(":"))
|
|
52
|
+
return false;
|
|
53
|
+
return words.split(/\s+/).length <= MAX_LABEL_WORDS;
|
|
54
|
+
}
|
|
55
|
+
function labelKind(line) {
|
|
56
|
+
const t = line.trim();
|
|
57
|
+
if (RULE.test(t))
|
|
58
|
+
return "rule";
|
|
59
|
+
const heading = HEADING.exec(t);
|
|
60
|
+
if (heading)
|
|
61
|
+
return isLabelText(heading[1] ?? "") ? "heading" : null;
|
|
62
|
+
const emphasis = EMPHASIS.exec(t);
|
|
63
|
+
if (emphasis)
|
|
64
|
+
return isLabelText(emphasis[2] ?? "") ? "label" : null;
|
|
65
|
+
// A plain line that only introduces what follows: "Mögliche Rückfragen:".
|
|
66
|
+
if (t.endsWith(":") && !/^[-*+>|`]|^\d+[.)]/.test(t))
|
|
67
|
+
return isLabelText(t) ? "label" : null;
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Drop a heading, a bold or italic label, or a horizontal rule that sits
|
|
72
|
+
* directly above the replies. The reply buttons are their own label; a
|
|
73
|
+
* heading over them is the model narrating the interface, and in front of
|
|
74
|
+
* the buttons it reads as an empty section. Safe on any text: a real
|
|
75
|
+
* paragraph is never touched, and a label line that ends a paragraph
|
|
76
|
+
* (no blank line above it) belongs to that paragraph and stays.
|
|
77
|
+
*/
|
|
78
|
+
export function dropReplyLabel(text) {
|
|
79
|
+
const lines = text.trimEnd().split("\n");
|
|
80
|
+
let droppedLabel = false;
|
|
81
|
+
for (let guard = 0; guard < 4 && lines.length > 0; guard++) {
|
|
82
|
+
const i = lines.length - 1;
|
|
83
|
+
const kind = labelKind(lines[i] ?? "");
|
|
84
|
+
if (!kind)
|
|
85
|
+
break;
|
|
86
|
+
const alone = i === 0 || (lines[i - 1] ?? "").trim() === "";
|
|
87
|
+
if (kind === "label" && !alone)
|
|
88
|
+
break;
|
|
89
|
+
if (kind !== "rule") {
|
|
90
|
+
if (droppedLabel)
|
|
91
|
+
break;
|
|
92
|
+
droppedLabel = true;
|
|
93
|
+
}
|
|
94
|
+
lines.pop();
|
|
95
|
+
while (lines.length > 0 && (lines[lines.length - 1] ?? "").trim() === "")
|
|
96
|
+
lines.pop();
|
|
97
|
+
}
|
|
98
|
+
return lines.join("\n");
|
|
99
|
+
}
|
|
100
|
+
// While streaming: could this last line still become a label? Starts like a
|
|
101
|
+
// heading, an emphasis run or a rule, and is short enough to be one.
|
|
102
|
+
function mayBecomeLabel(line) {
|
|
103
|
+
const t = line.trim();
|
|
104
|
+
if (/^[-*_]{1,3}$/.test(t))
|
|
105
|
+
return true;
|
|
106
|
+
if (!/^(?:#{1,6}(?:\s|$)|\*{1,3}(?!\s)|_{1,3}(?!\s))/.test(t))
|
|
107
|
+
return false;
|
|
108
|
+
return isLabelText(t.replace(/^#+\s*/, "")) || labelKind(t) !== null;
|
|
109
|
+
}
|
|
110
|
+
function holdBack(text) {
|
|
111
|
+
let rest = text.replace(/\n?```\s*$/, "").trimEnd();
|
|
112
|
+
rest = dropReplyLabel(rest);
|
|
113
|
+
const lines = rest.split("\n");
|
|
114
|
+
const last = lines[lines.length - 1] ?? "";
|
|
115
|
+
const alone = lines.length === 1 || (lines[lines.length - 2] ?? "").trim() === "";
|
|
116
|
+
if (alone && mayBecomeLabel(last)) {
|
|
117
|
+
lines.pop();
|
|
118
|
+
return lines.join("\n").trimEnd();
|
|
119
|
+
}
|
|
120
|
+
return rest;
|
|
121
|
+
}
|
|
39
122
|
function clean(raw, { max = 4, maxLength = 48 }) {
|
|
40
123
|
let parsed;
|
|
41
124
|
try {
|
|
@@ -73,15 +156,20 @@ function clean(raw, { max = 4, maxLength = 48 }) {
|
|
|
73
156
|
export function extractReplies(text, options = {}) {
|
|
74
157
|
const match = COMPLETE.exec(text);
|
|
75
158
|
if (match) {
|
|
76
|
-
const
|
|
77
|
-
|
|
159
|
+
const replies = clean(match[1] ?? "", options);
|
|
160
|
+
const before = text.slice(0, match.index);
|
|
161
|
+
const after = text.slice(match.index + match[0].length);
|
|
162
|
+
const rest = ((replies.length > 0 ? dropReplyLabel(before) : before) + after).trimEnd();
|
|
163
|
+
return { text: rest, replies };
|
|
78
164
|
}
|
|
79
165
|
const tail = OPEN_TAIL.exec(text);
|
|
80
166
|
// A bare ``` at the end may be the start of an ordinary code block; only
|
|
81
167
|
// hide it while it could still become ours.
|
|
82
168
|
if (tail && tail[0].trim() !== "```") {
|
|
83
|
-
return { text: text.slice(0, tail.index)
|
|
169
|
+
return { text: dropReplyLabel(text.slice(0, tail.index)), replies: [] };
|
|
84
170
|
}
|
|
171
|
+
if (options.streaming)
|
|
172
|
+
return { text: holdBack(text), replies: [] };
|
|
85
173
|
return { text, replies: [] };
|
|
86
174
|
}
|
|
87
175
|
//# sourceMappingURL=replies.js.map
|
package/dist/replies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replies.js","sourceRoot":"","sources":["../src/replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"replies.js","sourceRoot":"","sources":["../src/replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAgB7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,sBAAsB;IACtB,0LAA0L;IAC1L,KAAK,GAAG,aAAa;IACrB,4CAA4C;IAC5C,KAAK;IACL,0eAA0e;CAC3e,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,SAAS,GAAG,aAAa,GAAG,qBAAqB,EAAE,GAAG,CAAC,CAAC;AACpF,4EAA4E;AAC5E,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,YAAY,GAAG,aAAa,GAAG,uBAAuB,EAAE,GAAG,CAAC,CAAC;AAE1F,4EAA4E;AAC5E,wEAAwE;AACxE,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,kEAAkE;AAClE,MAAM,OAAO,GAAG,4BAA4B,CAAC;AAC7C,MAAM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AE,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IACD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,yEAAyE;IACzE,4CAA4C;IAC5C,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,CAAC,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACpE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/rich.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { type ChartBlock } from "./chart.js";
|
|
2
|
+
export * from "./chart.js";
|
|
1
3
|
/** Declarative answer blocks. Model output is data, never HTML or executable SVG. */
|
|
2
|
-
export type RichBlock =
|
|
4
|
+
export type RichBlock =
|
|
5
|
+
/** A figure drawn by the app's injected renderer (see chart.ts). */
|
|
6
|
+
ChartBlock | {
|
|
3
7
|
type: "audio";
|
|
4
8
|
title: string;
|
|
5
9
|
src: string;
|
package/dist/rich.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich.d.ts","sourceRoot":"","sources":["../src/rich.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"rich.d.ts","sourceRoot":"","sources":["../src/rich.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAExF,cAAc,YAAY,CAAC;AAE3B,qFAAqF;AACrF,MAAM,MAAM,SAAS;AACnB,oEAAoE;AAClE,UAAU,GACV;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACjF;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,GAC5F;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxD,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvD,GACD;IAA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M,wBAAwB,QAczB,CAAC;AAEb,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqCnD"}
|
package/dist/rich.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { chartFallback, chartText, parseChartBlock } from "./chart.js";
|
|
2
|
+
export * from "./chart.js";
|
|
1
3
|
/** The icons a stack tile may carry — a closed set, so a name is never markup. */
|
|
2
4
|
export const STACK_ICONS = [
|
|
3
5
|
"agent",
|
|
@@ -45,7 +47,11 @@ export function parseRichBlock(raw) {
|
|
|
45
47
|
catch {
|
|
46
48
|
return null;
|
|
47
49
|
}
|
|
48
|
-
if (!record(b)
|
|
50
|
+
if (!record(b))
|
|
51
|
+
return null;
|
|
52
|
+
if (b.type === "chart")
|
|
53
|
+
return parseChartBlock(b);
|
|
54
|
+
if (!str(b.title, 200))
|
|
49
55
|
return null;
|
|
50
56
|
switch (b.type) {
|
|
51
57
|
case "audio":
|
|
@@ -119,15 +125,25 @@ export const RICH_ANSWERS_INSTRUCTION = [
|
|
|
119
125
|
'{"type":"stack","title":"The complete architecture","layers":[{"nodes":[{"kicker":"USER","label":"Build this","detail":"One conversation, one goal"}],"link":"the goal"},{"nodes":[{"kicker":"CONTROL PLANE","label":"Plan · Dispatch · Verify","tone":"accent"}],"link":"work orders","both":true},{"nodes":[{"icon":"agent","label":"AI agents","detail":"Code, research"},{"icon":"people","label":"People","detail":"Specialists"},{"icon":"robot","label":"Robots","detail":"Move, inspect"}]}],"caption":"Proposed logical architecture — not a claim that every connection exists today."}',
|
|
120
126
|
'{"type":"callout","title":"Recommendation","body":"The useful takeaway."}',
|
|
121
127
|
'{"type":"choices","title":"What would you like next?","options":[{"label":"Explain the first option","reply":"Explain the first option"},{"label":"Compare the alternatives","reply":"Compare the alternatives"}],"submit":"Continue"}',
|
|
128
|
+
'{"type":"chart","chart":"bars","caption":"Gallium production, 2024","unit":"t","highlight":"China","rows":[{"label":"China","value":750,"share":98,"href":"/atlas/china"},{"label":"Japan","value":10,"estimated":true,"note":"Optional"}]}',
|
|
129
|
+
'Other charts, same envelope: "share" with "rows":[{"label","share"(0–100),"href"?}] and "other"?; "line" with "series":[{"id","label","points":[{"x","y","href"?,"note"?}]}]; "timeline" with "events":[{"date","label","href"?,"tone":"up|down|neutral"?}]; "tiles" with "tiles":[{"label","value","href"?,"note"?}].',
|
|
130
|
+
"Draw a chart instead of a list when the figures are there: ranked quantities with 3 or more rows → bars; shares of one whole → share; a quantity over time with 3 or more points → line; 3 or more dated events → timeline; 2–4 headline figures → tiles. Every number comes from a tool result in this conversation — never from memory, and never a chart for a figure the tools did not return. Copy each row's href from the result's page or link, and leave it out when there is none. Say the takeaway in prose too; a reader without the figure still gets the answer.",
|
|
122
131
|
"Use a stack for an architecture, a pipeline or layers of responsibility (top to bottom, at most 8 layers of at most 4 tiles; icons only from: agent, people, robot, person, building, money, document, code, check, globe, wrench, box, chat, flag); use a diagram for an arbitrary graph. When you lay out a few approaches to choose from, write them as a numbered list whose items open with a bold name, and mark the one you recommend with [Recommended] right after the name. Use at most 6 images, 8 diagram nodes, 16 edges, or 6 choices per block. Translate titles, labels and submit into the reader's language. A choice sends its reply as a normal message; it never performs an action directly. Audio uses explicit playback, never autoplay. Include audio only for URLs actually provided by a person, context or a completed tool result; a track title or a planned generation is not a playable file. Preserve creator attribution and distinguish previews, generated drafts and finished recordings. Never invent media URLs, numbers, sources, tool results or product capabilities. Use only image URLs provided by the person, context or tools; otherwise use a diagram or plain text. Always explain the takeaway in prose too. No HTML, scripts, raw SVG, or decorative images. Preserve domain-specific evidence and authority rules. Put suggested replies last, outside chat_ui blocks.",
|
|
123
132
|
].join("\n");
|
|
124
133
|
/** Copy, share and voice keep the content of a visual, never its wire JSON. */
|
|
125
134
|
export function richAnswerText(text) {
|
|
126
135
|
return text.replace(/```chat_ui\s*([\s\S]*?)(?:```|$)/g, (_, raw) => {
|
|
127
136
|
const b = parseRichBlock(raw);
|
|
128
|
-
if (!b)
|
|
129
|
-
|
|
137
|
+
if (!b) {
|
|
138
|
+
// A malformed chart reads as its caption and rows, the way it renders.
|
|
139
|
+
const t = chartFallback(raw);
|
|
140
|
+
return t
|
|
141
|
+
? `${t.caption}\n${t.rows.map((r) => r.cells.filter(Boolean).join(" — ")).join("\n")}`
|
|
142
|
+
: "";
|
|
143
|
+
}
|
|
130
144
|
switch (b.type) {
|
|
145
|
+
case "chart":
|
|
146
|
+
return chartText(b);
|
|
131
147
|
case "audio":
|
|
132
148
|
return `${b.title}${b.creator ? ` — ${b.creator}` : ""}${b.caption ? `\n${b.caption}` : ""}\n${b.src}`;
|
|
133
149
|
case "callout":
|