rift-ds 1.21.0 → 1.22.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/chat/AssistantTurn.js +4 -2
- package/chat/ChatLauncher.js +3 -0
- package/chat/ChatWidget.d.ts +3 -1
- package/chat/ChatWidget.js +13 -7
- package/chat/TurnContent.d.ts +3 -3
- package/chat/agentState.d.ts +14 -0
- package/chat/agentState.js +29 -0
- package/chat/artifacts.d.ts +5 -0
- package/chat/artifacts.js +3 -1
- package/chat/index.d.ts +1 -0
- package/chat/index.js +2 -0
- package/chat/server.js +5 -0
- package/chat/types.d.ts +12 -2
- package/chat/useChat.js +16 -5
- package/components/Composer/Composer.css +21 -18
- package/components/Composer/Composer.d.ts +4 -4
- package/components/Composer/Composer.js +3 -2
- package/components/TableToolbar/TableToolbar.js +0 -2
- package/components/ThemeToggle/colorMode.d.ts +10 -0
- package/components/ThemeToggle/colorMode.js +19 -5
- package/package.json +1 -1
package/chat/AssistantTurn.js
CHANGED
|
@@ -12,6 +12,7 @@ import { useChatWidget } from "./context.js";
|
|
|
12
12
|
import { DOCK_QUERY } from "./queries.js";
|
|
13
13
|
import { FollowupSuggestions } from "./FollowupSuggestions.js";
|
|
14
14
|
import { ResponseActions } from "./ResponseActions.js";
|
|
15
|
+
import { turnCards } from "./artifacts.js";
|
|
15
16
|
import { TurnCard } from "./TurnContent.js";
|
|
16
17
|
import { TurnQuestion } from "./TurnQuestion.js";
|
|
17
18
|
const CodeBlockLabelsContext = createContext(void 0);
|
|
@@ -60,7 +61,8 @@ function AssistantTurn({
|
|
|
60
61
|
const durationSeconds = live ? live.durationSeconds : turn?.durationSeconds;
|
|
61
62
|
const text = live ? live.text : turn?.text ?? "";
|
|
62
63
|
const content = live ? live.content : turn?.content;
|
|
63
|
-
const
|
|
64
|
+
const source = live ?? turn;
|
|
65
|
+
const cards = source ? turnCards(source) : [];
|
|
64
66
|
const { turns, live: liveTurn, freshFollowupsId } = useChatWidget();
|
|
65
67
|
const followupsPending = !!turn && turn.text !== "" && !!turn.exchangeId && !turn.followups && !turn.question && !liveTurn && turns[turns.length - 1]?.id === turn.id;
|
|
66
68
|
return /* @__PURE__ */ jsx(
|
|
@@ -92,7 +94,7 @@ function AssistantTurn({
|
|
|
92
94
|
}
|
|
93
95
|
),
|
|
94
96
|
content,
|
|
95
|
-
card
|
|
97
|
+
cards.map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index)),
|
|
96
98
|
text !== "" && /* @__PURE__ */ jsx(CodeBlockLabelsContext.Provider, { value: labels?.codeBlock, children: /* @__PURE__ */ jsx(Prose, { children: /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], components: markdownComponents, children: text }) }) }),
|
|
97
99
|
turn?.question && /* @__PURE__ */ jsx(TurnQuestion, { turn, labels: labels?.questionCard })
|
|
98
100
|
] })
|
package/chat/ChatLauncher.js
CHANGED
|
@@ -4,6 +4,7 @@ import { useSyncExternalStore, useLayoutEffect, useRef, useEffect, useState } fr
|
|
|
4
4
|
import { useScrollLock } from "../behaviors/useScrollLock.js";
|
|
5
5
|
import { AiButton } from "../components/AiButton/AiButton.js";
|
|
6
6
|
import { ChatWidget } from "./ChatWidget.js";
|
|
7
|
+
import { useChatAgentState } from "./agentState.js";
|
|
7
8
|
import { useChatWidget } from "./context.js";
|
|
8
9
|
import { isFloatDragStart, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, dockWidthFromDrag, clampFloatPosition } from "./placement.js";
|
|
9
10
|
import { DOCK_QUERY, TAKEOVER_QUERY } from "./queries.js";
|
|
@@ -48,6 +49,7 @@ function ChatLauncher({
|
|
|
48
49
|
surface = "raised"
|
|
49
50
|
}) {
|
|
50
51
|
const { open, setOpen, panelPhase, view, side, floating, returnFocusRef, send } = useChatWidget();
|
|
52
|
+
const agentState = useChatAgentState();
|
|
51
53
|
const launchSuggestion = (id) => {
|
|
52
54
|
const chip = summary?.chips?.find((c) => c.id === id);
|
|
53
55
|
if (!chip) return;
|
|
@@ -251,6 +253,7 @@ function ChatLauncher({
|
|
|
251
253
|
...aiButtonLabels,
|
|
252
254
|
label,
|
|
253
255
|
icon,
|
|
256
|
+
state: agentState,
|
|
254
257
|
"aria-expanded": false,
|
|
255
258
|
"aria-controls": panelId,
|
|
256
259
|
summary: summary ? {
|
package/chat/ChatWidget.d.ts
CHANGED
|
@@ -114,6 +114,8 @@ export interface ChatWidgetProps {
|
|
|
114
114
|
artifacts?: boolean;
|
|
115
115
|
/** The composer's context note, naming what the chat is looking at. Omit for none. The note's wording comes from `contextNote`. */
|
|
116
116
|
contextLabel?: string | null;
|
|
117
|
+
/** Where the context note sits: `above` the composer, or `inside` it, at the top of the shell, which brings the two-row composer. */
|
|
118
|
+
contextPlacement?: 'above' | 'inside';
|
|
117
119
|
/** The composer's context note, written from `contextLabel`. Defaults to `Looking at “<title>”`. */
|
|
118
120
|
contextNote?: (title: string) => string;
|
|
119
121
|
/** The second line of the drop overlay with attachments on, written from the limits: the largest file as text ("50 MB"), the most files per message, and the largest file in bytes for a host that formats sizes itself. Defaults to `Up to <maxSize> each · <maxFiles> files max`. */
|
|
@@ -226,4 +228,4 @@ export interface ChatWidgetProps {
|
|
|
226
228
|
* a stage card, a whole page). It reads all of its state from ChatProvider,
|
|
227
229
|
* so the conversation is the same object wherever it shows.
|
|
228
230
|
*/
|
|
229
|
-
export declare function ChatWidget({ fullscreenEnabled, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, contextLabel, contextNote, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
|
|
231
|
+
export declare function ChatWidget({ fullscreenEnabled, closeEnabled, placementEnabled, compact, phone, title, flow, placeholder, questionsPlaceholder, showStarters, logo, tagline, starters: startersInput, startersKey, composerActions, models, defaultModel, lockedModelDescription, fileAttachments, maxAttachments, maxAttachmentBytes, mentions, threads, threadsProps, tabs, aside, agent, artifacts, contextLabel, contextNote, contextPlacement, attachHint: attachHintText, greetings, placementLabels, agentStatus, artifactPanelTitle, artifactEmptyTitle, artifactEmptyDescription, widgets, widgetsLayout, widgetsWidth, disclaimer, startersLabel, newChatLabel, showAgentLabel, hideAgentLabel, closeAgentLabel, showArtifactLabel, hideArtifactLabel, closeArtifactLabel, placementLabel, enterFullscreenLabel, exitFullscreenLabel, closeLabel, openThreadsLabel, closeThreadsLabel, modelPickerLabel, sendLabel, copyResponseLabel, copiedResponseLabel, copiedAnnouncementLabel, goodResponseLabel, badResponseLabel, followupsLabel, pastedTextLabel, reasoningLabel, tabsProps, composerLabels, attachmentDropZoneLabels, attachmentGroupLabels, chatThreadLabels, modelPickerLabels, artifactPanelLabels, agentRailLabels, questionCardLabels, questionSummaryLabels, codeBlockLabels, promptSuggestionsLabels, }: ChatWidgetProps): import("react").JSX.Element;
|
package/chat/ChatWidget.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ModelPicker } from "../components/ModelPicker/ModelPicker.js";
|
|
|
16
16
|
import { PromptSuggestions } from "../components/PromptSuggestions/PromptSuggestions.js";
|
|
17
17
|
import { MOTION_SUGGESTIONS_THINK_MS, MOTION_SCROLL_SETTLE_MS } from "../tokens/motion.js";
|
|
18
18
|
import { AssistantTurn } from "./AssistantTurn.js";
|
|
19
|
-
import { cardArtifact } from "./artifacts.js";
|
|
19
|
+
import { turnCards, cardArtifact } from "./artifacts.js";
|
|
20
20
|
import { ChatAgentPane } from "./ChatAgentPane.js";
|
|
21
21
|
import { ChatArtifactPane } from "./ChatArtifactPane.js";
|
|
22
22
|
import { ChatTabs } from "./ChatTabs.js";
|
|
@@ -72,6 +72,7 @@ function ChatWidget({
|
|
|
72
72
|
artifacts = false,
|
|
73
73
|
contextLabel,
|
|
74
74
|
contextNote = defaultContextNote,
|
|
75
|
+
contextPlacement = "above",
|
|
75
76
|
attachHint: attachHintText = defaultAttachHint,
|
|
76
77
|
greetings,
|
|
77
78
|
placementLabels,
|
|
@@ -175,6 +176,7 @@ function ChatWidget({
|
|
|
175
176
|
const lockedValues = modelPolicy?.locked ?? [];
|
|
176
177
|
const pick = chosenModel && !lockedValues.includes(chosenModel) ? chosenModel : null;
|
|
177
178
|
const pickerValue = pick ?? modelPolicy?.default ?? defaultModel ?? models?.[0]?.value;
|
|
179
|
+
const composerHasActions = fileAttachments || Boolean(composerActions) || (models?.length ?? 0) > 0 || Boolean(contextLabel) && contextPlacement === "inside";
|
|
178
180
|
const pickerModels = (models ?? []).map((option) => ({
|
|
179
181
|
value: option.value,
|
|
180
182
|
label: option.label,
|
|
@@ -309,8 +311,11 @@ function ChatWidget({
|
|
|
309
311
|
};
|
|
310
312
|
const latestArtifact = useMemo(() => {
|
|
311
313
|
for (let index = turns.length - 1; index >= 0; index -= 1) {
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
+
const cards = turnCards(turns[index]);
|
|
315
|
+
for (let card = cards.length - 1; card >= 0; card -= 1) {
|
|
316
|
+
const found = cardArtifact(cards[card]);
|
|
317
|
+
if (found) return found;
|
|
318
|
+
}
|
|
314
319
|
}
|
|
315
320
|
return null;
|
|
316
321
|
}, [turns]);
|
|
@@ -321,7 +326,7 @@ function ChatWidget({
|
|
|
321
326
|
}, [asideWide]);
|
|
322
327
|
useEffect(() => {
|
|
323
328
|
if (!artifacts) return;
|
|
324
|
-
const carrying = turns.filter((turn) =>
|
|
329
|
+
const carrying = turns.filter((turn) => turnCards(turn).some((card) => cardArtifact(card)));
|
|
325
330
|
if (seenArtifactTurns.current === null) {
|
|
326
331
|
seenArtifactTurns.current = new Set(carrying.map((turn) => turn.id));
|
|
327
332
|
return;
|
|
@@ -329,7 +334,7 @@ function ChatWidget({
|
|
|
329
334
|
for (const turn of carrying) {
|
|
330
335
|
if (seenArtifactTurns.current.has(turn.id)) continue;
|
|
331
336
|
seenArtifactTurns.current.add(turn.id);
|
|
332
|
-
const arrived =
|
|
337
|
+
const arrived = turnCards(turn).map((card) => cardArtifact(card)).filter(Boolean).pop();
|
|
333
338
|
if (arrived && asideWideRef.current) openArtifact(arrived);
|
|
334
339
|
}
|
|
335
340
|
}, [artifacts, turns, openArtifact]);
|
|
@@ -571,7 +576,7 @@ function ChatWidget({
|
|
|
571
576
|
role: "user",
|
|
572
577
|
attachments: turn.attachments ? /* @__PURE__ */ jsx(AttachmentGroup, { ...attachmentGroupLabels, align: "end", items: turn.attachments }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
573
578
|
turn.content,
|
|
574
|
-
turn.card
|
|
579
|
+
turnCards(turn).map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index))
|
|
575
580
|
] }),
|
|
576
581
|
children: turn.reply ? /* @__PURE__ */ jsx(ReplyBody, { reply: turn.reply, text: turn.text, missingLabel: questionSummaryLabels?.missingLabel }) : mentions && turn.text ? /* @__PURE__ */ jsx(MentionText, { text: turn.text, sources: mentions }) : turn.text
|
|
577
582
|
},
|
|
@@ -597,6 +602,7 @@ function ChatWidget({
|
|
|
597
602
|
placeholder: questionsOpen ? questionsPlaceholder : placeholder,
|
|
598
603
|
disabled: questionsOpen,
|
|
599
604
|
sendLabel,
|
|
605
|
+
inline: composerHasActions ? false : "chat",
|
|
600
606
|
aiGlow: true,
|
|
601
607
|
value: draft,
|
|
602
608
|
onValueChange: setDraft,
|
|
@@ -605,7 +611,7 @@ function ChatWidget({
|
|
|
605
611
|
onStop: stop,
|
|
606
612
|
context: contextLabel ? contextNote(contextLabel) : void 0,
|
|
607
613
|
contextIcon: "description",
|
|
608
|
-
contextPlacement
|
|
614
|
+
contextPlacement,
|
|
609
615
|
mentions,
|
|
610
616
|
...fileAttachments ? {
|
|
611
617
|
files: queue.items,
|
package/chat/TurnContent.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ChatCard } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* renderer draws nothing
|
|
5
|
-
*
|
|
3
|
+
* One of a turn's cards, drawn through the provider's renderers. A kind with
|
|
4
|
+
* no renderer draws nothing, so an unknown kind degrades to the words alone,
|
|
5
|
+
* or to nothing on a reply that is only a card. The one
|
|
6
6
|
* built-in kind is the artifact, drawn as its tile unless the host has
|
|
7
7
|
* taken the kind over with a renderer of its own.
|
|
8
8
|
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AgentStatusState } from '../components/AgentStatus/AgentStatusPatterns';
|
|
2
|
+
/**
|
|
3
|
+
* What the agent is doing right now, in AgentStatus's vocabulary, for whatever
|
|
4
|
+
* opens the chat: pass it to an AiButton's `state`, so a reply keeps showing
|
|
5
|
+
* its progress on the button after the panel is closed. Read it under a
|
|
6
|
+
* ChatProvider, from something that stays mounted while the panel is open, so
|
|
7
|
+
* the end of a reply is only reported once.
|
|
8
|
+
*
|
|
9
|
+
* `thinking` until the first words, `working` once words or rich content are
|
|
10
|
+
* arriving, `waiting` while a question stands unanswered, then `done` or
|
|
11
|
+
* `error` for a beat as a reply ends. A reply the visitor stopped, or a chat
|
|
12
|
+
* they reset, goes straight back to `idle`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useChatAgentState(): AgentStatusState;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { MOTION_FEEDBACK_RESET_MS } from "../tokens/motion.js";
|
|
4
|
+
import { useChatWidget } from "./context.js";
|
|
5
|
+
function useChatAgentState() {
|
|
6
|
+
const { live, turns } = useChatWidget();
|
|
7
|
+
const [ended, setEnded] = useState(null);
|
|
8
|
+
const last = turns[turns.length - 1];
|
|
9
|
+
const inFlight = live !== null;
|
|
10
|
+
const [wasInFlight, setWasInFlight] = useState(inFlight);
|
|
11
|
+
if (wasInFlight !== inFlight) {
|
|
12
|
+
setWasInFlight(inFlight);
|
|
13
|
+
const reported = !inFlight && last?.role === "assistant" && last.outcome !== "stopped";
|
|
14
|
+
setEnded(reported ? last.outcome === "failed" ? "error" : "done" : null);
|
|
15
|
+
}
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!ended) return;
|
|
18
|
+
const timer = setTimeout(() => setEnded(null), MOTION_FEEDBACK_RESET_MS);
|
|
19
|
+
return () => clearTimeout(timer);
|
|
20
|
+
}, [ended]);
|
|
21
|
+
if (live) {
|
|
22
|
+
return live.phase === "thinking" && !live.content && !live.cards?.length ? "thinking" : "working";
|
|
23
|
+
}
|
|
24
|
+
if (last?.role === "assistant" && last.question && !last.answers) return "waiting";
|
|
25
|
+
return ended ?? "idle";
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
useChatAgentState
|
|
29
|
+
};
|
package/chat/artifacts.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ChatArtifact, ChatCard } from './types';
|
|
2
2
|
/** The artifact a card carries, or null when it is some other kind of card. */
|
|
3
3
|
export declare const cardArtifact: (card: ChatCard | undefined) => ChatArtifact | null;
|
|
4
|
+
/** The cards a turn draws: all it carried, or the one set by hand. */
|
|
5
|
+
export declare const turnCards: (turn: {
|
|
6
|
+
card?: ChatCard;
|
|
7
|
+
cards?: ChatCard[];
|
|
8
|
+
}) => ChatCard[];
|
|
4
9
|
/** Wraps an artifact as the card a transport sends. */
|
|
5
10
|
export declare const artifactCard: (artifact: ChatArtifact) => ChatCard;
|
package/chat/artifacts.js
CHANGED
|
@@ -4,11 +4,13 @@ const isArtifact = (data) => {
|
|
|
4
4
|
return typeof candidate === "object" && candidate !== null && typeof candidate.id === "string" && typeof candidate.title === "string" && typeof candidate.kind === "string";
|
|
5
5
|
};
|
|
6
6
|
const cardArtifact = (card) => card?.kind === ARTIFACT_CARD_KIND && isArtifact(card.data) ? card.data : null;
|
|
7
|
+
const turnCards = (turn) => turn.cards ?? (turn.card ? [turn.card] : []);
|
|
7
8
|
const artifactCard = (artifact) => ({
|
|
8
9
|
kind: ARTIFACT_CARD_KIND,
|
|
9
10
|
data: artifact
|
|
10
11
|
});
|
|
11
12
|
export {
|
|
12
13
|
artifactCard,
|
|
13
|
-
cardArtifact
|
|
14
|
+
cardArtifact,
|
|
15
|
+
turnCards
|
|
14
16
|
};
|
package/chat/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
export { ChatProvider, type ChatProviderProps } from './ChatProvider';
|
|
17
17
|
export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type RailSlot } from './ChatWidget';
|
|
18
18
|
export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
|
|
19
|
+
export { useChatAgentState } from './agentState';
|
|
19
20
|
export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
|
|
20
21
|
export { ChatTabs, type ChatTabsProps } from './ChatTabs';
|
|
21
22
|
export { ChatAgentPane, type ChatAgentPaneProps } from './ChatAgentPane';
|
package/chat/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChatProvider } from "./ChatProvider.js";
|
|
2
2
|
import { ChatWidget } from "./ChatWidget.js";
|
|
3
3
|
import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
|
|
4
|
+
import { useChatAgentState } from "./agentState.js";
|
|
4
5
|
import { ChatThreads } from "./ChatThreads.js";
|
|
5
6
|
import { ChatTabs } from "./ChatTabs.js";
|
|
6
7
|
import { ChatAgentPane } from "./ChatAgentPane.js";
|
|
@@ -95,6 +96,7 @@ export {
|
|
|
95
96
|
serverGreeting,
|
|
96
97
|
subscribeClock,
|
|
97
98
|
useChat,
|
|
99
|
+
useChatAgentState,
|
|
98
100
|
useChatWidget,
|
|
99
101
|
useTakeoverViewport,
|
|
100
102
|
useThreads
|
package/chat/server.js
CHANGED
|
@@ -252,6 +252,7 @@ function createChatHandler(options) {
|
|
|
252
252
|
let final;
|
|
253
253
|
for (let call = 0; ; call += 1) {
|
|
254
254
|
const lastCall = call === maxModelCalls - 1;
|
|
255
|
+
let passWroteText = false;
|
|
255
256
|
const stream = client.messages.stream(
|
|
256
257
|
{
|
|
257
258
|
model: serving.id,
|
|
@@ -277,7 +278,11 @@ function createChatHandler(options) {
|
|
|
277
278
|
reasoning.close();
|
|
278
279
|
streamedText = true;
|
|
279
280
|
firstTextMs = Date.now() - startedAt;
|
|
281
|
+
} else if (!passWroteText && answerText !== "") {
|
|
282
|
+
answerText += "\n\n";
|
|
283
|
+
send({ type: "delta", text: "\n\n" });
|
|
280
284
|
}
|
|
285
|
+
passWroteText = true;
|
|
281
286
|
answerText += event.delta.text;
|
|
282
287
|
send({ type: "delta", text: event.delta.text });
|
|
283
288
|
} else if (event.delta.type === "thinking_delta") {
|
package/chat/types.d.ts
CHANGED
|
@@ -219,9 +219,15 @@ export interface ChatTurn {
|
|
|
219
219
|
content?: ReactNode;
|
|
220
220
|
/**
|
|
221
221
|
* Rich content rendered with the turn through the provider's `renderers`,
|
|
222
|
-
* carried from a transport's `card` event. Drawn where `content` is
|
|
222
|
+
* carried from a transport's `card` event. Drawn where `content` is, and
|
|
223
|
+
* enough on its own: a reply may be a card with no text. With several, this
|
|
224
|
+
* is the latest.
|
|
223
225
|
*/
|
|
224
226
|
card?: ChatCard;
|
|
227
|
+
/** Every card the reply carried, in arrival order. Absent on a turn set by hand with `card`, which draws that one. */
|
|
228
|
+
cards?: ChatCard[];
|
|
229
|
+
/** How the reply ended, when it did not simply finish: `failed` for a failure the visitor was shown, `stopped` when they stopped it. */
|
|
230
|
+
outcome?: 'failed' | 'stopped';
|
|
225
231
|
/**
|
|
226
232
|
* Questions this assistant turn asks, drawn under it as a QuestionCard in
|
|
227
233
|
* place of follow-ups. Carried from a transport's `question` event.
|
|
@@ -270,8 +276,12 @@ export interface LiveResponse {
|
|
|
270
276
|
followups?: string[];
|
|
271
277
|
/** The transport's `content` event, drawn on the live reply and carried into the committed turn. */
|
|
272
278
|
content?: ReactNode;
|
|
273
|
-
/** The transport's `card` event, drawn on the live reply and carried into the committed turn. */
|
|
279
|
+
/** The transport's latest `card` event, drawn on the live reply and carried into the committed turn. */
|
|
274
280
|
card?: ChatCard;
|
|
281
|
+
/** Every `card` event so far, in arrival order, carried into the committed turn. */
|
|
282
|
+
cards?: ChatCard[];
|
|
283
|
+
/** How the reply ended, when it did not simply finish, carried into the committed turn. */
|
|
284
|
+
outcome?: 'failed' | 'stopped';
|
|
275
285
|
/** Carried from the transport's `question` event into the committed turn. */
|
|
276
286
|
question?: ChatQuestionSet;
|
|
277
287
|
}
|
package/chat/useChat.js
CHANGED
|
@@ -52,6 +52,8 @@ function useChat(transport, placeholders = DEFAULT_PLACEHOLDER_COPY) {
|
|
|
52
52
|
followups: finished.followups,
|
|
53
53
|
content: finished.content,
|
|
54
54
|
card: finished.card,
|
|
55
|
+
cards: finished.cards,
|
|
56
|
+
outcome: finished.outcome,
|
|
55
57
|
question: finished.question,
|
|
56
58
|
durationSeconds: finished.durationSeconds ?? Math.max(1, Math.round((Date.now() - startedAt) / 1e3))
|
|
57
59
|
}
|
|
@@ -128,7 +130,7 @@ function useChat(transport, placeholders = DEFAULT_PLACEHOLDER_COPY) {
|
|
|
128
130
|
update({ ...current, content: event.node });
|
|
129
131
|
break;
|
|
130
132
|
case "card":
|
|
131
|
-
update({ ...current, card: event.card });
|
|
133
|
+
update({ ...current, card: event.card, cards: [...current.cards ?? [], event.card] });
|
|
132
134
|
break;
|
|
133
135
|
case "question": {
|
|
134
136
|
const set = sanitizeQuestionSet(event.set, `${current.id}-questions`);
|
|
@@ -158,7 +160,8 @@ function useChat(transport, placeholders = DEFAULT_PLACEHOLDER_COPY) {
|
|
|
158
160
|
current = {
|
|
159
161
|
...current,
|
|
160
162
|
phase: "streaming",
|
|
161
|
-
durationSeconds: current.durationSeconds ?? 1
|
|
163
|
+
durationSeconds: current.durationSeconds ?? 1,
|
|
164
|
+
outcome: event.type === "error" ? "failed" : current.outcome
|
|
162
165
|
};
|
|
163
166
|
reveal.showWhole(event.type === "notice" ? event.text : event.message);
|
|
164
167
|
break;
|
|
@@ -174,21 +177,29 @@ function useChat(transport, placeholders = DEFAULT_PLACEHOLDER_COPY) {
|
|
|
174
177
|
}
|
|
175
178
|
reveal.cancel();
|
|
176
179
|
if (generation !== generationRef.current) return;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
const stopped = controller.signal.aborted;
|
|
181
|
+
if (stopped) current = { ...current, outcome: "stopped" };
|
|
182
|
+
if (current.text !== "") {
|
|
180
183
|
commit(current, startedAt, current.text);
|
|
184
|
+
} else if (current.content || current.cards?.length || current.question) {
|
|
185
|
+
commit(current, startedAt, null);
|
|
186
|
+
} else if (stopped) {
|
|
187
|
+
commit({ ...current, text: placeholders.stopped }, startedAt, null);
|
|
188
|
+
} else {
|
|
189
|
+
commit({ ...current, text: placeholders.empty, outcome: "failed" }, startedAt, null);
|
|
181
190
|
}
|
|
182
191
|
} catch (err) {
|
|
183
192
|
reveal.flush();
|
|
184
193
|
if (generation !== generationRef.current) ;
|
|
185
194
|
else if (controller.signal.aborted) {
|
|
195
|
+
current = { ...current, outcome: "stopped" };
|
|
186
196
|
if (current.text === "") {
|
|
187
197
|
commit({ ...current, text: placeholders.stopped }, startedAt, null);
|
|
188
198
|
} else {
|
|
189
199
|
commit(current, startedAt, current.text);
|
|
190
200
|
}
|
|
191
201
|
} else {
|
|
202
|
+
current = { ...current, outcome: "failed" };
|
|
192
203
|
if (current.text === "") {
|
|
193
204
|
commit({ ...current, text: placeholders.failed }, startedAt, null);
|
|
194
205
|
} else {
|
|
@@ -465,7 +465,7 @@
|
|
|
465
465
|
color: var(--color-input-text-primary);
|
|
466
466
|
/* Growth cap: the shell owns the block padding, so the cap is rows × line-height.
|
|
467
467
|
--ds-composer-max-rows is set inline from the maxRows prop. */
|
|
468
|
-
max-height: calc(var(--ds-composer-max-rows,
|
|
468
|
+
max-height: calc(var(--ds-composer-max-rows, 12) * var(--font-paragraph-line-height));
|
|
469
469
|
overflow-y: auto;
|
|
470
470
|
}
|
|
471
471
|
|
|
@@ -635,35 +635,22 @@
|
|
|
635
635
|
}
|
|
636
636
|
|
|
637
637
|
/* ============================================
|
|
638
|
-
COMPACT: the
|
|
638
|
+
COMPACT: the mini composer's smaller text. Its height and button are in the
|
|
639
|
+
INLINE section below; no other composer takes this density.
|
|
639
640
|
============================================ */
|
|
640
641
|
.ds-composer--compact {
|
|
641
|
-
--ds-composer-send-size: var(--control-height-compact);
|
|
642
642
|
--ds-composer-text-inset: var(--padding-300);
|
|
643
|
-
/* Concentric on this density's tighter ring. */
|
|
644
|
-
--ds-composer-radius: calc(
|
|
645
|
-
min(var(--radius-pill), var(--ds-composer-send-size) / 2) + var(--padding-100) + var(--border-025)
|
|
646
|
-
);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
.ds-composer--compact .ds-composer__content {
|
|
650
|
-
padding-block: var(--padding-200) var(--padding-100);
|
|
651
|
-
height: calc(var(--ds-composer-text-height, var(--font-paragraph-sm-line-height)) + var(--padding-200) + var(--padding-100));
|
|
652
643
|
}
|
|
653
644
|
|
|
654
645
|
.ds-composer--compact .ds-composer__textarea {
|
|
655
646
|
font-size: var(--font-paragraph-sm-size);
|
|
656
647
|
line-height: var(--font-paragraph-sm-line-height);
|
|
657
648
|
letter-spacing: var(--font-paragraph-sm-letter-spacing);
|
|
658
|
-
max-height: calc(var(--ds-composer-max-rows,
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
.ds-composer--compact .ds-composer__footer {
|
|
662
|
-
padding: var(--padding-100);
|
|
649
|
+
max-height: calc(var(--ds-composer-max-rows, 12) * var(--font-paragraph-sm-line-height));
|
|
663
650
|
}
|
|
664
651
|
|
|
665
652
|
/* ============================================
|
|
666
|
-
INLINE: one row at the control height
|
|
653
|
+
INLINE: one row at the control height, growing up to `maxRows`, the send
|
|
667
654
|
button on the text's line.
|
|
668
655
|
The shell is an input here, so it does not float, and the button sits
|
|
669
656
|
inside the height, concentric on a thinner ring.
|
|
@@ -745,3 +732,19 @@
|
|
|
745
732
|
width: var(--ds-composer-send-size);
|
|
746
733
|
height: var(--ds-composer-send-size);
|
|
747
734
|
}
|
|
735
|
+
|
|
736
|
+
/* INLINE IN A CHAT: the same one row, built out from a full-size send button
|
|
737
|
+
rather than down from a control height, because this is the page's main
|
|
738
|
+
input and not a field lined up with others. */
|
|
739
|
+
.ds-composer--inline-chat {
|
|
740
|
+
--ds-composer-ring: var(--padding-150);
|
|
741
|
+
--ds-composer-send-size: var(--control-height-default);
|
|
742
|
+
--ds-composer-control: calc(var(--ds-composer-send-size) + var(--ds-composer-ring) * 2 + var(--border-025) * 2);
|
|
743
|
+
--ds-composer-radius: calc(
|
|
744
|
+
min(var(--radius-pill), var(--ds-composer-send-size) / 2) + var(--ds-composer-ring) + var(--border-025)
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
.ds-composer--inline-chat .ds-composer__footer {
|
|
749
|
+
padding: var(--ds-composer-ring);
|
|
750
|
+
}
|
|
@@ -32,11 +32,11 @@ type ComposerOwnProps = {
|
|
|
32
32
|
streaming?: boolean;
|
|
33
33
|
/** Fires when the stop button is pressed while `streaming`. */
|
|
34
34
|
onStop?: () => void;
|
|
35
|
-
/** The density, matching a table's or a bar's: `compact`
|
|
35
|
+
/** The mini composer's density (`inline` as `true`), matching a table's or a bar's: `compact` takes the smaller text, height and button. Every other composer has the one size, so it ignores this. */
|
|
36
36
|
size?: 'default' | 'compact';
|
|
37
|
-
/** One row with the send button on the text's line
|
|
38
|
-
inline?: boolean;
|
|
39
|
-
/** Growth cap in text rows before the textarea scrolls internally. Defaults to
|
|
37
|
+
/** One row with the send button on the text's line. `true` makes the shell exactly `size`'s control height, so it lines up with an Input or a table's toolbar: the mini composer, for AI input inside other content such as a table, never for a chat. `chat` gives the button a full-size control and room around it: for a chat with nothing to seat in a footer. Above one row (`maxRows`), typing grows the shell with the send button held in the bottom corner. A placeholder stays on one line and ends in an ellipsis. */
|
|
38
|
+
inline?: boolean | 'chat';
|
|
39
|
+
/** Growth cap in text rows before the textarea scrolls internally. Defaults to 12 in a chat composer, or 3 in the mini composer. */
|
|
40
40
|
maxRows?: number;
|
|
41
41
|
/**
|
|
42
42
|
* While focused, the shell wears AiButton's slowly rotating gradient ring
|
|
@@ -36,7 +36,7 @@ const Composer = React.forwardRef(
|
|
|
36
36
|
onStop,
|
|
37
37
|
size = "default",
|
|
38
38
|
inline = false,
|
|
39
|
-
maxRows = inline ?
|
|
39
|
+
maxRows = inline === true ? 3 : 12,
|
|
40
40
|
aiGlow = false,
|
|
41
41
|
context,
|
|
42
42
|
contextIcon,
|
|
@@ -364,8 +364,9 @@ const Composer = React.forwardRef(
|
|
|
364
364
|
const classes = [
|
|
365
365
|
baseClass,
|
|
366
366
|
aiGlow ? `${baseClass}--ai-glow` : "",
|
|
367
|
-
size === "compact" ? `${baseClass}--compact` : "",
|
|
367
|
+
inline === true && size === "compact" ? `${baseClass}--compact` : "",
|
|
368
368
|
inline ? `${baseClass}--inline` : "",
|
|
369
|
+
inline === "chat" ? `${baseClass}--inline-chat` : "",
|
|
369
370
|
streaming ? `${baseClass}--streaming` : "",
|
|
370
371
|
disabled ? `${baseClass}--disabled` : "",
|
|
371
372
|
dragging ? `${baseClass}--dragging` : "",
|
|
@@ -140,7 +140,6 @@ function ToolbarPanel({
|
|
|
140
140
|
)
|
|
141
141
|
] });
|
|
142
142
|
}
|
|
143
|
-
const COMMAND_MAX_ROWS = 3;
|
|
144
143
|
function CommandRow({ command, table, labels, size, open, onClose, state, onStateChange }) {
|
|
145
144
|
const { toast, dismiss } = useToast();
|
|
146
145
|
const [text, setText] = useState("");
|
|
@@ -255,7 +254,6 @@ function CommandRow({ command, table, labels, size, open, onClose, state, onStat
|
|
|
255
254
|
Composer,
|
|
256
255
|
{
|
|
257
256
|
inline: true,
|
|
258
|
-
maxRows: COMMAND_MAX_ROWS,
|
|
259
257
|
size,
|
|
260
258
|
value: text,
|
|
261
259
|
onValueChange: setText,
|
|
@@ -38,5 +38,15 @@ export type ColorModeOptions = {
|
|
|
38
38
|
* is `system`, keeps `data-theme` following the operating system. Render it
|
|
39
39
|
* inline in the document head, before anything paints. Storage being
|
|
40
40
|
* unavailable (a private window) leaves the page on `system`.
|
|
41
|
+
*
|
|
42
|
+
* It also puts the choice back when React wipes it. A hydration failure that
|
|
43
|
+
* reaches the root (a browser extension editing the page before hydration
|
|
44
|
+
* is enough) makes React client-render `<html>`, and taking that element
|
|
45
|
+
* over removes every attribute on it before setting the ones the layout
|
|
46
|
+
* renders. Without a repair the visitor's mode falls back to whatever the
|
|
47
|
+
* layout wrote, or to light. The script watches for its own
|
|
48
|
+
* `data-theme-setting` going missing, or coming back from nothing, and
|
|
49
|
+
* applies the stored choice again. A ThemeToggle change only ever replaces
|
|
50
|
+
* the value, so it never trips the repair.
|
|
41
51
|
*/
|
|
42
52
|
export declare function colorModeScript({ storageKey }?: ColorModeOptions): string;
|
|
@@ -5,17 +5,31 @@ function colorModeScript({ storageKey = DEFAULT_COLOR_MODE_STORAGE_KEY } = {}) {
|
|
|
5
5
|
const key = JSON.stringify(storageKey);
|
|
6
6
|
return `(function () {
|
|
7
7
|
var root = document.documentElement;
|
|
8
|
-
var saved = null;
|
|
9
|
-
try { saved = localStorage.getItem(${key}); } catch (e) {}
|
|
10
|
-
var setting = saved === 'light' || saved === 'dark' ? saved : 'system';
|
|
11
8
|
var media = window.matchMedia('(prefers-color-scheme: dark)');
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
function apply() {
|
|
10
|
+
var saved = null;
|
|
11
|
+
try { saved = localStorage.getItem(${key}); } catch (e) {}
|
|
12
|
+
var setting = saved === 'light' || saved === 'dark' ? saved : 'system';
|
|
13
|
+
root.setAttribute('data-theme-setting', setting);
|
|
14
|
+
root.setAttribute('data-theme', setting === 'system' ? (media.matches ? 'dark' : 'light') : setting);
|
|
15
|
+
}
|
|
16
|
+
apply();
|
|
14
17
|
media.addEventListener('change', function (event) {
|
|
15
18
|
if (root.getAttribute('data-theme-setting') === 'system') {
|
|
16
19
|
root.setAttribute('data-theme', event.matches ? 'dark' : 'light');
|
|
17
20
|
}
|
|
18
21
|
});
|
|
22
|
+
if (typeof MutationObserver === 'undefined') return;
|
|
23
|
+
var observer = new MutationObserver(function (records) {
|
|
24
|
+
var wiped = !root.hasAttribute('data-theme-setting');
|
|
25
|
+
for (var i = 0; !wiped && i < records.length; i++) {
|
|
26
|
+
if (records[i].attributeName === 'data-theme-setting' && records[i].oldValue === null) wiped = true;
|
|
27
|
+
}
|
|
28
|
+
if (!wiped) return;
|
|
29
|
+
apply();
|
|
30
|
+
observer.takeRecords();
|
|
31
|
+
});
|
|
32
|
+
observer.observe(root, { attributes: true, attributeOldValue: true, attributeFilter: ['data-theme-setting'] });
|
|
19
33
|
})();`;
|
|
20
34
|
}
|
|
21
35
|
export {
|
package/package.json
CHANGED