rift-ds 1.22.0 → 1.24.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/README.md +3 -3
- package/behaviors/chat-card.css +135 -0
- package/behaviors/shell.css +119 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +69 -15
- package/bin/templates/blocks/components/blocks/AppShell.tsx +45 -30
- package/bin/templates/blocks/registry.json +1 -1
- package/chat/AssistantTurn.js +9 -3
- package/chat/ChatAgentPane.css +6 -6
- package/chat/ChatLauncher.d.ts +3 -3
- package/chat/ChatLauncher.js +3 -5
- package/chat/ChatProvider.d.ts +10 -1
- package/chat/ChatProvider.js +3 -2
- package/chat/ChatWidget.css +272 -8
- package/chat/ChatWidget.d.ts +63 -9
- package/chat/ChatWidget.js +110 -38
- package/chat/DemoWelcome.js +2 -2
- package/chat/actions.d.ts +105 -0
- package/chat/actions.js +47 -0
- package/chat/demo-card-components.d.ts +3 -4
- package/chat/demo-script.js +15 -15
- package/chat/generatedStarters.d.ts +19 -0
- package/chat/generatedStarters.js +49 -0
- package/chat/index.d.ts +7 -3
- package/chat/index.js +25 -2
- package/chat/placement.d.ts +9 -0
- package/chat/placement.js +7 -0
- package/chat/queries.d.ts +6 -0
- package/chat/queries.js +25 -0
- package/chat/questions.d.ts +1 -1
- package/chat/questions.js +1 -1
- package/chat/registry.json.d.ts +5 -3
- package/chat/registry.json.js +1 -1
- package/chat/selection.css +8 -0
- package/chat/selection.d.ts +40 -0
- package/chat/selection.js +140 -0
- package/chat/selectionContext.d.ts +70 -0
- package/chat/selectionContext.js +60 -0
- package/chat/server.d.ts +54 -1
- package/chat/server.js +101 -5
- package/chat/suggestions.d.ts +12 -8
- package/chat/suggestions.js +1 -1
- package/chat/types.d.ts +2 -0
- package/chat/useChat.js +5 -3
- package/components/ActionCard/ActionCard.css +147 -0
- package/components/ActionCard/ActionCard.d.ts +54 -0
- package/components/ActionCard/ActionCard.js +75 -0
- package/components/ActionReadout/ActionReadout.css +47 -0
- package/components/ActionReadout/ActionReadout.d.ts +29 -0
- package/components/ActionReadout/ActionReadout.js +22 -0
- package/components/AgentPlan/AgentPlan.css +18 -8
- package/components/AgentPlan/AgentPlan.js +1 -0
- package/components/AppLayout/AppLayout.css +17 -4
- package/components/AppLayout/AppLayout.d.ts +8 -5
- package/components/AppLayout/AppLayout.js +2 -0
- package/components/AppSidebar/AppSidebar.css +119 -28
- package/components/AppSidebar/AppSidebar.d.ts +10 -5
- package/components/AppSidebar/AppSidebar.js +19 -4
- package/components/ArtifactCard/ArtifactCard.css +11 -10
- package/components/ArtifactCard/ArtifactCard.js +3 -1
- package/components/ChatThread/ChatThread.css +6 -3
- package/components/Chip/Chip.css +9 -1
- package/components/CodeBlock/CodeBlock.css +2 -0
- package/components/CodeDiff/CodeDiff.css +18 -8
- package/components/CodeDiff/CodeDiff.js +1 -0
- package/components/Composer/Composer.css +52 -13
- package/components/Composer/Composer.d.ts +9 -1
- package/components/Composer/Composer.js +19 -1
- package/components/DataTable/FilterEditor.js +4 -2
- package/components/DataTable/filterModel.d.ts +8 -0
- package/components/DataTable/filterModel.js +4 -0
- package/components/DataTable/views.js +2 -2
- package/components/DocumentChip/DocumentChip.css +27 -3
- package/components/EntitySwitcher/EntitySwitcher.css +333 -0
- package/components/EntitySwitcher/EntitySwitcher.d.ts +74 -0
- package/components/EntitySwitcher/EntitySwitcher.js +291 -0
- package/components/InterruptCard/InterruptCard.css +96 -34
- package/components/InterruptCard/InterruptCard.d.ts +20 -3
- package/components/InterruptCard/InterruptCard.js +23 -8
- package/components/MessageCard/MessageCard.css +27 -18
- package/components/MessageCard/MessageCard.js +1 -0
- package/components/PromptSuggestions/PromptSuggestions.css +3 -0
- package/components/Prose/Prose.css +2 -0
- package/components/QuestionCard/QuestionCard.css +9 -5
- package/components/QuestionCard/QuestionCard.js +1 -0
- package/components/SourceTrail/SourceTrail.css +33 -11
- package/components/SourceTrail/SourceTrail.js +3 -2
- package/components/TableToolbar/TableToolbar.css +4 -1
- package/components/TableToolbar/TableToolbar.js +1 -1
- package/components/ThemePicker/ThemePicker.css +6 -0
- package/components/ThemePicker/ThemePicker.js +20 -11
- package/components/ThreadPanel/ThreadPanel.css +65 -36
- package/components/ThreadPanel/ThreadPanel.d.ts +5 -5
- package/components/ThreadPanel/ThreadPanel.js +1 -1
- package/components/ToolCall/ToolCall.css +89 -22
- package/components/ToolCall/ToolCall.js +2 -1
- package/components/UsageCard/UsageCard.css +29 -2
- package/components/UsageCard/UsageCard.js +1 -0
- package/components/registry.json +25 -1
- package/components/registry.json.d.ts +25 -1
- package/components/registry.json.js +1 -1
- package/fonts/presets/bricolage-grotesque-300-800-latin-ext.woff2 +0 -0
- package/fonts/presets/bricolage-grotesque-300-800-latin.woff2 +0 -0
- package/fonts/presets/figtree-300-800-latin-ext.woff2 +0 -0
- package/fonts/presets/figtree-300-800-latin.woff2 +0 -0
- package/index.d.ts +3 -0
- package/index.js +6 -0
- package/package.json +5 -1
- package/tokens/motion.d.ts +2 -0
- package/tokens/motion.js +2 -0
- package/tokens/presets/plum.css +413 -0
- package/tokens/presets/presets.css +1 -0
- package/tokens/registry.json +2 -0
- package/tokens/registry.json.d.ts +2 -0
- package/tokens/registry.json.js +1 -1
- package/tokens/tokens-dark.css +6 -2
- package/tokens/tokens-light.css +6 -2
- package/tokens/tokens-typography.css +8 -2
- package/tokens/values.json.js +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { MOTION_SELECTION_SETTLE_MS } from "../tokens/motion.js";
|
|
4
|
+
const written = /* @__PURE__ */ new Map();
|
|
5
|
+
function hashOf(text) {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
for (let index = 0; index < text.length; index += 1) hash = hash * 31 + text.charCodeAt(index) | 0;
|
|
8
|
+
return (hash >>> 0).toString(36);
|
|
9
|
+
}
|
|
10
|
+
function useGeneratedStarters(request, { endpoint, active, fallback }) {
|
|
11
|
+
const cacheKey = request === null ? null : `${endpoint}
|
|
12
|
+
${request}`;
|
|
13
|
+
const [settled, setSettled] = useState(null);
|
|
14
|
+
const fallbackRef = useRef(fallback);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
fallbackRef.current = fallback;
|
|
17
|
+
});
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!active || cacheKey === null || written.has(cacheKey)) return;
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const timer = setTimeout(async () => {
|
|
22
|
+
let suggestions = [];
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(endpoint, {
|
|
25
|
+
method: "POST",
|
|
26
|
+
headers: { "content-type": "application/json" },
|
|
27
|
+
body: JSON.stringify({ context: request }),
|
|
28
|
+
signal: controller.signal
|
|
29
|
+
});
|
|
30
|
+
suggestions = response.ok ? (await response.json()).suggestions ?? [] : [];
|
|
31
|
+
} catch {
|
|
32
|
+
if (controller.signal.aborted) return;
|
|
33
|
+
}
|
|
34
|
+
const starters2 = suggestions.length ? suggestions.map((label, index) => ({ id: `generated-${index}`, label })) : fallbackRef.current;
|
|
35
|
+
written.set(cacheKey, starters2);
|
|
36
|
+
setSettled({ cacheKey, starters: starters2 });
|
|
37
|
+
}, MOTION_SELECTION_SETTLE_MS);
|
|
38
|
+
return () => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
controller.abort();
|
|
41
|
+
};
|
|
42
|
+
}, [active, cacheKey, endpoint, request]);
|
|
43
|
+
if (cacheKey === null) return { starters: null, pending: false, key: null };
|
|
44
|
+
const starters = written.get(cacheKey) ?? (settled?.cacheKey === cacheKey ? settled.starters : null);
|
|
45
|
+
return { starters: starters ?? fallback, pending: active && !starters, key: `generated-${hashOf(cacheKey)}` };
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
useGeneratedStarters
|
|
49
|
+
};
|
package/chat/index.d.ts
CHANGED
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
* documentation, and validate-chat-widget.mjs holds the two together).
|
|
15
15
|
*/
|
|
16
16
|
export { ChatProvider, type ChatProviderProps } from './ChatProvider';
|
|
17
|
-
export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type RailSlot } from './ChatWidget';
|
|
17
|
+
export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type ChatBackdrop, type ChatContext, type ChatLayout, type RailSlot } from './ChatWidget';
|
|
18
|
+
export { useSelectionFocus, useHeldHighlight, readSelection, describeSelection, CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, type SelectedText, type DescribeSelectionOptions } from './selection';
|
|
19
|
+
export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatSelection, type SelectionKind, type SelectionLimits, type SelectionLinesOptions } from './selectionContext';
|
|
20
|
+
export { useGeneratedStarters, type GeneratedStarters, type GeneratedStartersOptions } from './generatedStarters';
|
|
21
|
+
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, } from './actions';
|
|
18
22
|
export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
|
|
19
23
|
export { useChatAgentState } from './agentState';
|
|
20
24
|
export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
|
|
@@ -23,7 +27,7 @@ export { ChatAgentPane, type ChatAgentPaneProps } from './ChatAgentPane';
|
|
|
23
27
|
export { ChatArtifactPane, type ChatArtifactPaneProps } from './ChatArtifactPane';
|
|
24
28
|
export { ChatArtifactCard, type ChatArtifactCardProps } from './ChatArtifactCard';
|
|
25
29
|
export { useChatWidget, isInternalPath, createFeedbackPoster, type ChatView, type ChatArtifactRenderers, type ChatCardRenderers, type ChatLinkRenderer, type ChatWidgetContextValue, type FeedbackSink, } from './context';
|
|
26
|
-
export { DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, useTakeoverViewport, } from './queries';
|
|
30
|
+
export { DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, useTakeoverViewport, useDockViewport, } from './queries';
|
|
27
31
|
export { useChat, DEFAULT_PLACEHOLDER_COPY, type ChatState, type ChatPlaceholderCopy, } from './useChat';
|
|
28
32
|
export { useThreads, THREAD_NAMING_DELAY_MS, type ThreadsLabels, type ThreadsOptions, type ThreadsState } from './threads';
|
|
29
33
|
export { createFetchTransport, DEFAULT_FETCH_COPY, FIRST_BYTE_TIMEOUT_MS, MAX_TRANSPORT_TURNS, type FetchTransportOptions, type FetchTransportCopy, } from './transport';
|
|
@@ -33,7 +37,7 @@ export { SUGGESTION_MAX_CHARS, fitsChip } from './suggestions';
|
|
|
33
37
|
export { sanitizeQuestionSet, describeAnswers, serializeReply, isBlockingQuestion, ASK_USER_INPUT_SCHEMA, MAX_QUESTIONS, MAX_QUESTION_OPTIONS, MIN_QUESTION_OPTIONS, QUESTION_PROMPT_MAX_CHARS, OPTION_DESCRIPTION_MAX_CHARS, } from './questions';
|
|
34
38
|
export { STARTER_COUNT, pickStarters, namedStarter, hashString, mulberry32, } from './starters';
|
|
35
39
|
export { greetingFor, readGreeting, serverGreeting, subscribeClock, DEFAULT_GREETING_COPY, type GreetingCopy, } from './greeting';
|
|
36
|
-
export { CHAT_PLACEMENTS, chatPlacement, DOCK_MIN_WIDTH, DOCK_MAX_WIDTH, FLOAT_MAX_SCALE, FLOAT_EDGE_GAP, dockWidthFromDrag, isFloatDragStart, clampFloatPosition, type ChatPlacement, type ChatSide, } from './placement';
|
|
40
|
+
export { CHAT_PLACEMENTS, chatPlacement, DOCK_MIN_WIDTH, DOCK_MAX_WIDTH, DOCK_PAGE_MIN_WIDTH, dockFits, FLOAT_MAX_SCALE, FLOAT_EDGE_GAP, dockWidthFromDrag, isFloatDragStart, clampFloatPosition, type ChatPlacement, type ChatSide, } from './placement';
|
|
37
41
|
export { artifactCard, cardArtifact } from './artifacts';
|
|
38
42
|
export { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS, type ChatArtifact, type ChatCard, type ChatEvent, type ChatQuestion, type ChatQuestionAnswer, type ChatQuestionSet, type ChatReply, type ChatTransport, type ChatTransportMessage, type ChatTurn, type ChatModelOption, type ChatFeedbackVerdict, type LivePhase, type LiveResponse, type Starter, } from './types';
|
|
39
43
|
export { chatWidget, chatWidgetRegistry, WIDGET_COUNT, type ChatWidgetMeta } from './registry';
|
package/chat/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ChatProvider } from "./ChatProvider.js";
|
|
2
2
|
import { ChatWidget } from "./ChatWidget.js";
|
|
3
|
+
import { CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, describeSelection, readSelection, useHeldHighlight, useSelectionFocus } from "./selection.js";
|
|
4
|
+
import { DEFAULT_SELECTION_LIMITS, sanitiseSelection, selectionLines } from "./selectionContext.js";
|
|
5
|
+
import { useGeneratedStarters } from "./generatedStarters.js";
|
|
6
|
+
import { confirmationLine, createConfirmationMark, defineAction, planAction, sanitiseConfirmation, skippedText } from "./actions.js";
|
|
3
7
|
import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
|
|
4
8
|
import { useChatAgentState } from "./agentState.js";
|
|
5
9
|
import { ChatThreads } from "./ChatThreads.js";
|
|
@@ -8,7 +12,7 @@ import { ChatAgentPane } from "./ChatAgentPane.js";
|
|
|
8
12
|
import { ChatArtifactPane } from "./ChatArtifactPane.js";
|
|
9
13
|
import { ChatArtifactCard } from "./ChatArtifactCard.js";
|
|
10
14
|
import { createFeedbackPoster, isInternalPath, useChatWidget } from "./context.js";
|
|
11
|
-
import { ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, useTakeoverViewport } from "./queries.js";
|
|
15
|
+
import { ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH, ASIDE_WITH_THREADS_MIN_WIDTH, DOCK_QUERY, TAKEOVER_QUERY, THREADS_RAIL_MIN_WIDTH, useDockViewport, useTakeoverViewport } from "./queries.js";
|
|
12
16
|
import { DEFAULT_PLACEHOLDER_COPY, useChat } from "./useChat.js";
|
|
13
17
|
import { THREAD_NAMING_DELAY_MS, useThreads } from "./threads.js";
|
|
14
18
|
import { DEFAULT_FETCH_COPY, FIRST_BYTE_TIMEOUT_MS, MAX_TRANSPORT_TURNS, createFetchTransport } from "./transport.js";
|
|
@@ -18,7 +22,7 @@ import { SUGGESTION_MAX_CHARS, fitsChip } from "./suggestions.js";
|
|
|
18
22
|
import { ASK_USER_INPUT_SCHEMA, MAX_QUESTIONS, MAX_QUESTION_OPTIONS, MIN_QUESTION_OPTIONS, OPTION_DESCRIPTION_MAX_CHARS, QUESTION_PROMPT_MAX_CHARS, describeAnswers, isBlockingQuestion, sanitizeQuestionSet, serializeReply } from "./questions.js";
|
|
19
23
|
import { STARTER_COUNT, hashString, mulberry32, namedStarter, pickStarters } from "./starters.js";
|
|
20
24
|
import { DEFAULT_GREETING_COPY, greetingFor, readGreeting, serverGreeting, subscribeClock } from "./greeting.js";
|
|
21
|
-
import { CHAT_PLACEMENTS, DOCK_MAX_WIDTH, DOCK_MIN_WIDTH, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, chatPlacement, clampFloatPosition, dockWidthFromDrag, isFloatDragStart } from "./placement.js";
|
|
25
|
+
import { CHAT_PLACEMENTS, DOCK_MAX_WIDTH, DOCK_MIN_WIDTH, DOCK_PAGE_MIN_WIDTH, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, chatPlacement, clampFloatPosition, dockFits, dockWidthFromDrag, isFloatDragStart } from "./placement.js";
|
|
22
26
|
import { artifactCard, cardArtifact } from "./artifacts.js";
|
|
23
27
|
import { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS } from "./types.js";
|
|
24
28
|
import { WIDGET_COUNT, chatWidget, chatWidgetRegistry } from "./registry.js";
|
|
@@ -31,6 +35,7 @@ export {
|
|
|
31
35
|
CHAT_EVENT_KINDS,
|
|
32
36
|
CHAT_PANEL_ID,
|
|
33
37
|
CHAT_PLACEMENTS,
|
|
38
|
+
CHAT_SOURCE_ATTRIBUTE,
|
|
34
39
|
ChatAgentPane,
|
|
35
40
|
ChatArtifactCard,
|
|
36
41
|
ChatArtifactPane,
|
|
@@ -44,14 +49,17 @@ export {
|
|
|
44
49
|
DEFAULT_FETCH_COPY,
|
|
45
50
|
DEFAULT_GREETING_COPY,
|
|
46
51
|
DEFAULT_PLACEHOLDER_COPY,
|
|
52
|
+
DEFAULT_SELECTION_LIMITS,
|
|
47
53
|
DEFAULT_SIM_TIMING,
|
|
48
54
|
DOCK_MAX_WIDTH,
|
|
49
55
|
DOCK_MIN_WIDTH,
|
|
56
|
+
DOCK_PAGE_MIN_WIDTH,
|
|
50
57
|
DOCK_QUERY,
|
|
51
58
|
FIRST_BYTE_TIMEOUT_MS,
|
|
52
59
|
FLOAT_EDGE_GAP,
|
|
53
60
|
FLOAT_MAX_SCALE,
|
|
54
61
|
FOLLOWUPS_TIMEOUT_MS,
|
|
62
|
+
HELD_HIGHLIGHT_NAME,
|
|
55
63
|
MAX_FOLLOWUPS,
|
|
56
64
|
MAX_QUESTIONS,
|
|
57
65
|
MAX_QUESTION_OPTIONS,
|
|
@@ -71,12 +79,17 @@ export {
|
|
|
71
79
|
chatWidget,
|
|
72
80
|
chatWidgetRegistry,
|
|
73
81
|
clampFloatPosition,
|
|
82
|
+
confirmationLine,
|
|
83
|
+
createConfirmationMark,
|
|
74
84
|
createFeedbackPoster,
|
|
75
85
|
createFetchTransport,
|
|
76
86
|
createFollowupsFetcher,
|
|
77
87
|
createSimTransport,
|
|
78
88
|
defaultFilesReply,
|
|
89
|
+
defineAction,
|
|
79
90
|
describeAnswers,
|
|
91
|
+
describeSelection,
|
|
92
|
+
dockFits,
|
|
80
93
|
dockWidthFromDrag,
|
|
81
94
|
fitsChip,
|
|
82
95
|
followupTarget,
|
|
@@ -89,15 +102,25 @@ export {
|
|
|
89
102
|
namedStarter,
|
|
90
103
|
pickFallbackFollowups,
|
|
91
104
|
pickStarters,
|
|
105
|
+
planAction,
|
|
92
106
|
readGreeting,
|
|
107
|
+
readSelection,
|
|
108
|
+
sanitiseConfirmation,
|
|
109
|
+
sanitiseSelection,
|
|
93
110
|
sanitizeQuestionSet,
|
|
94
111
|
scriptChat,
|
|
112
|
+
selectionLines,
|
|
95
113
|
serializeReply,
|
|
96
114
|
serverGreeting,
|
|
115
|
+
skippedText,
|
|
97
116
|
subscribeClock,
|
|
98
117
|
useChat,
|
|
99
118
|
useChatAgentState,
|
|
100
119
|
useChatWidget,
|
|
120
|
+
useDockViewport,
|
|
121
|
+
useGeneratedStarters,
|
|
122
|
+
useHeldHighlight,
|
|
123
|
+
useSelectionFocus,
|
|
101
124
|
useTakeoverViewport,
|
|
102
125
|
useThreads
|
|
103
126
|
};
|
package/chat/placement.d.ts
CHANGED
|
@@ -25,6 +25,15 @@ export declare const chatPlacement: (id: ChatPlacement) => {
|
|
|
25
25
|
};
|
|
26
26
|
export declare const DOCK_MIN_WIDTH = 420;
|
|
27
27
|
export declare const DOCK_MAX_WIDTH = 655;
|
|
28
|
+
/** The page room the dock threshold promises: the narrowest viewport that
|
|
29
|
+
docks (the step plus the one pixel `mediaAbove` adds) less the panel's
|
|
30
|
+
resting width. */
|
|
31
|
+
export declare const DOCK_PAGE_MIN_WIDTH: number;
|
|
32
|
+
/** Whether a panel of this width docks in a viewport this wide: only while
|
|
33
|
+
the page keeps the room the dock threshold promises. A panel widened, or
|
|
34
|
+
a window narrowed, past it overlays instead, the rule below the dock
|
|
35
|
+
threshold. */
|
|
36
|
+
export declare function dockFits(viewportWidth: number, panelWidth: number): boolean;
|
|
28
37
|
/** A docked panel's width after a grip drag: the inner edge is the one
|
|
29
38
|
that moves, and it faces the other way on the left dock. */
|
|
30
39
|
export declare function dockWidthFromDrag(startWidth: number, pointerDelta: number, side: ChatSide): number;
|
package/chat/placement.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BREAKPOINT_CHAT_DOCK_PX } from "../tokens/breakpoints.js";
|
|
1
2
|
const CHAT_PLACEMENTS = [
|
|
2
3
|
{ id: "right", label: "Dock right", icon: "dock_to_left" },
|
|
3
4
|
{ id: "left", label: "Dock left", icon: "dock_to_right" },
|
|
@@ -6,6 +7,10 @@ const CHAT_PLACEMENTS = [
|
|
|
6
7
|
const chatPlacement = (id) => CHAT_PLACEMENTS.find((placement) => placement.id === id) ?? CHAT_PLACEMENTS[0];
|
|
7
8
|
const DOCK_MIN_WIDTH = 420;
|
|
8
9
|
const DOCK_MAX_WIDTH = 655;
|
|
10
|
+
const DOCK_PAGE_MIN_WIDTH = BREAKPOINT_CHAT_DOCK_PX + 1 - DOCK_MIN_WIDTH;
|
|
11
|
+
function dockFits(viewportWidth, panelWidth) {
|
|
12
|
+
return viewportWidth - panelWidth >= DOCK_PAGE_MIN_WIDTH;
|
|
13
|
+
}
|
|
9
14
|
function dockWidthFromDrag(startWidth, pointerDelta, side) {
|
|
10
15
|
const grown = startWidth + (side === "left" ? pointerDelta : -pointerDelta);
|
|
11
16
|
return Math.round(Math.min(DOCK_MAX_WIDTH, Math.max(DOCK_MIN_WIDTH, grown)));
|
|
@@ -30,10 +35,12 @@ export {
|
|
|
30
35
|
CHAT_PLACEMENTS,
|
|
31
36
|
DOCK_MAX_WIDTH,
|
|
32
37
|
DOCK_MIN_WIDTH,
|
|
38
|
+
DOCK_PAGE_MIN_WIDTH,
|
|
33
39
|
FLOAT_EDGE_GAP,
|
|
34
40
|
FLOAT_MAX_SCALE,
|
|
35
41
|
chatPlacement,
|
|
36
42
|
clampFloatPosition,
|
|
43
|
+
dockFits,
|
|
37
44
|
dockWidthFromDrag,
|
|
38
45
|
isFloatDragStart
|
|
39
46
|
};
|
package/chat/queries.d.ts
CHANGED
|
@@ -16,3 +16,9 @@ export declare const ARTIFACT_MIN_COLUMN_WIDTH = 320;
|
|
|
16
16
|
server and for the first client render. Shared by the launcher and any
|
|
17
17
|
host stage, which both hand the widget its phone layout. */
|
|
18
18
|
export declare function useTakeoverViewport(): boolean;
|
|
19
|
+
/** Whether a chat panel docks beside the page now: above the dock threshold
|
|
20
|
+
and only while the page keeps the room that threshold promises, so a
|
|
21
|
+
panel widened past it overlays instead. False on the server and for the
|
|
22
|
+
first client render. Shared by the launcher and any host that reserves
|
|
23
|
+
the docked panel's room. */
|
|
24
|
+
export declare function useDockViewport(): boolean;
|
package/chat/queries.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useSyncExternalStore } from "react";
|
|
3
3
|
import { mediaAbove, mediaBelow, BREAKPOINT_CHAT_TAKEOVER_PX, BREAKPOINT_CHAT_DOCK_PX } from "../tokens/breakpoints.js";
|
|
4
|
+
import { DOCK_MIN_WIDTH, dockFits } from "./placement.js";
|
|
4
5
|
const DOCK_QUERY = mediaAbove(BREAKPOINT_CHAT_DOCK_PX);
|
|
5
6
|
const TAKEOVER_QUERY = mediaBelow(BREAKPOINT_CHAT_TAKEOVER_PX);
|
|
6
7
|
const THREADS_RAIL_MIN_WIDTH = 720;
|
|
@@ -16,6 +17,29 @@ const readTakeover = () => window.matchMedia(TAKEOVER_QUERY).matches;
|
|
|
16
17
|
function useTakeoverViewport() {
|
|
17
18
|
return useSyncExternalStore(subscribeTakeover, readTakeover, () => false);
|
|
18
19
|
}
|
|
20
|
+
let lastDockFit = false;
|
|
21
|
+
const readDockFit = () => {
|
|
22
|
+
const root = document.documentElement;
|
|
23
|
+
if (root.hasAttribute("data-chat-resizing")) return lastDockFit;
|
|
24
|
+
const width = parseFloat(root.style.getPropertyValue("--ds-chat-width")) || DOCK_MIN_WIDTH;
|
|
25
|
+
lastDockFit = window.matchMedia(DOCK_QUERY).matches && dockFits(window.innerWidth, width);
|
|
26
|
+
return lastDockFit;
|
|
27
|
+
};
|
|
28
|
+
const subscribeDockFit = (onChange) => {
|
|
29
|
+
window.addEventListener("resize", onChange);
|
|
30
|
+
const observer = new MutationObserver(onChange);
|
|
31
|
+
observer.observe(document.documentElement, {
|
|
32
|
+
attributes: true,
|
|
33
|
+
attributeFilter: ["style", "data-chat-resizing"]
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
window.removeEventListener("resize", onChange);
|
|
37
|
+
observer.disconnect();
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
function useDockViewport() {
|
|
41
|
+
return useSyncExternalStore(subscribeDockFit, readDockFit, () => false);
|
|
42
|
+
}
|
|
19
43
|
export {
|
|
20
44
|
ARTIFACT_MIN_COLUMN_WIDTH,
|
|
21
45
|
ASIDE_RAIL_MIN_WIDTH,
|
|
@@ -23,5 +47,6 @@ export {
|
|
|
23
47
|
DOCK_QUERY,
|
|
24
48
|
TAKEOVER_QUERY,
|
|
25
49
|
THREADS_RAIL_MIN_WIDTH,
|
|
50
|
+
useDockViewport,
|
|
26
51
|
useTakeoverViewport
|
|
27
52
|
};
|
package/chat/questions.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export declare const ASK_USER_INPUT_SCHEMA: {
|
|
|
66
66
|
readonly properties: {
|
|
67
67
|
readonly label: {
|
|
68
68
|
readonly type: "string";
|
|
69
|
-
readonly description: "The answer as the person would say it, at most
|
|
69
|
+
readonly description: "The answer as the person would say it, at most 30 characters, a month or weekday written short (\"Oct\").";
|
|
70
70
|
};
|
|
71
71
|
readonly description: {
|
|
72
72
|
readonly type: "string";
|
package/chat/questions.js
CHANGED
|
@@ -103,7 +103,7 @@ const ASK_USER_INPUT_SCHEMA = {
|
|
|
103
103
|
properties: {
|
|
104
104
|
label: {
|
|
105
105
|
type: "string",
|
|
106
|
-
description: `The answer as the person would say it, at most ${SUGGESTION_MAX_CHARS} characters.`
|
|
106
|
+
description: `The answer as the person would say it, at most ${SUGGESTION_MAX_CHARS} characters, a month or weekday written short ("Oct").`
|
|
107
107
|
},
|
|
108
108
|
description: {
|
|
109
109
|
type: "string",
|
package/chat/registry.json.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ declare const _default: {
|
|
|
6
6
|
"slug": "ai-chat",
|
|
7
7
|
"label": "AI chat",
|
|
8
8
|
"category": "ai",
|
|
9
|
-
"description": "The whole AI chat: the panel, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.",
|
|
9
|
+
"description": "The whole AI chat: the panel, or the page itself in an app shell mode, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.",
|
|
10
10
|
"command": "init chat",
|
|
11
11
|
"subpaths": {
|
|
12
|
-
"./chat": "The widget, the provider, the launcher and the engine under them.",
|
|
13
|
-
"./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions,
|
|
12
|
+
"./chat": "The widget, the provider, the launcher and the engine under them, with the hooks that let it follow the reader and write starters for what they picked.",
|
|
13
|
+
"./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, its follow-ups, starters and feedback siblings, and the checks for what a reader highlighted, for any web-standard route.",
|
|
14
|
+
"./chat/actions": "The action definitions a page and its route share, their dry run and the mark that says a change was confirmed on its card, with no dependencies.",
|
|
14
15
|
"./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.",
|
|
15
16
|
"./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.",
|
|
16
17
|
"./chat/chat.css": "The widget's stylesheet."
|
|
@@ -45,6 +46,7 @@ declare const _default: {
|
|
|
45
46
|
"CircularButton",
|
|
46
47
|
"CodeBlock",
|
|
47
48
|
"Composer",
|
|
49
|
+
"DocumentChip",
|
|
48
50
|
"DropdownMenu",
|
|
49
51
|
"EmptyState",
|
|
50
52
|
"Mention",
|
package/chat/registry.json.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const $comment = "The widget registry: the fourth kind of thing the package ships, between the components and the templates. One member by design. `parts` names the library components the widget composes (held to src/components/registry.json by scripts/validate-chat-widget.mjs), `subpaths` the package exports it occupies (held to scripts/package-manifest.mjs), `category` the component category whose section and sidebar group its page joins (held to src/components/registry.json), `peers` the optional peer dependencies each subpath needs (held to package.json). The widget's page under /components, the /docs/chat page, the chat corpus and the MCP tools read this file; never type its facts elsewhere.";
|
|
2
|
-
const widgets = [{ "name": "ChatWidget", "slug": "ai-chat", "label": "AI chat", "category": "ai", "description": "The whole AI chat: the panel, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.", "command": "init chat", "subpaths": { "./chat": "The widget, the provider, the launcher and the engine under them.", "./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions,
|
|
2
|
+
const widgets = [{ "name": "ChatWidget", "slug": "ai-chat", "label": "AI chat", "category": "ai", "description": "The whole AI chat: the panel, or the page itself in an app shell mode, the streaming replies, the history, the cards and questions a reply can carry and the server handlers, set up with props.", "command": "init chat", "subpaths": { "./chat": "The widget, the provider, the launcher and the engine under them, with the hooks that let it follow the reader and write starters for what they picked.", "./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, its follow-ups, starters and feedback siblings, and the checks for what a reader highlighted, for any web-standard route.", "./chat/actions": "The action definitions a page and its route share, their dry run and the mark that says a change was confirmed on its card, with no dependencies.", "./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.", "./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.", "./chat/chat.css": "The widget's stylesheet." }, "peers": { "./chat": ["react-markdown", "remark-gfm"], "./chat/server": ["@anthropic-ai/sdk"], "./chat/upstash": ["@upstash/ratelimit", "@upstash/redis"], "./chat/demo": ["recharts"] }, "parts": ["AgentRail", "AgentStatus", "AiButton", "ArtifactCard", "ArtifactPanel", "AttachmentDropZone", "AttachmentGroup", "ChatHeader", "ChatMessage", "ChatThread", "CircularButton", "CodeBlock", "Composer", "DocumentChip", "DropdownMenu", "EmptyState", "Mention", "ModelPicker", "PixelAvatar", "PromptSuggestions", "Prose", "QuestionCard", "Reasoning", "ThreadPanel", "ThreadTabs"], "documented": ["ChatWidget", "ChatProvider", "ChatLauncher", "ChatThreads", "ChatTabs", "ChatAgentPane", "ChatArtifactPane", "ChatArtifactCard"] }];
|
|
3
3
|
const registry = {
|
|
4
4
|
$comment,
|
|
5
5
|
widgets
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* The highlight a chat holds on the page while it is the chat's context
|
|
2
|
+
(useHeldHighlight in selection.ts): the context note's own fill, so the
|
|
3
|
+
passage and the note that names it read as one thing, and quieter than a
|
|
4
|
+
live selection, so it reads as held rather than active. */
|
|
5
|
+
::highlight(ds-chat-focus) {
|
|
6
|
+
background-color: var(--color-chat-context-bg);
|
|
7
|
+
color: var(--color-text-primary);
|
|
8
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { ChatSelection, SelectionLimits } from './selectionContext';
|
|
3
|
+
/** A highlight inside the root, as a chat reads it. */
|
|
4
|
+
export interface SelectedText {
|
|
5
|
+
/** The words, whitespace collapsed and icon ligature names left out. */
|
|
6
|
+
text: string;
|
|
7
|
+
/** A copy of the range, for `useHeldHighlight` to repaint. */
|
|
8
|
+
range: Range;
|
|
9
|
+
/** The smallest element that holds all of the highlight: where its source is read. */
|
|
10
|
+
holder: Element;
|
|
11
|
+
}
|
|
12
|
+
/** The attribute a host puts on an element to name what a highlight inside it is about. */
|
|
13
|
+
export declare const CHAT_SOURCE_ATTRIBUTE = "data-chat-source";
|
|
14
|
+
/** The highlight name `useHeldHighlight` paints, styled in selection.css. */
|
|
15
|
+
export declare const HELD_HIGHLIGHT_NAME = "ds-chat-focus";
|
|
16
|
+
/** Reads the current selection as a highlight inside `root`, or null when it is empty or elsewhere. */
|
|
17
|
+
export declare function readSelection(root: Element): SelectedText | null | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Calls `onSelect` with each highlight the reader makes inside `root`, and with
|
|
20
|
+
* null when one inside it collapses. A selection outside the root is ignored.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useSelectionFocus(root: RefObject<Element | null>, onSelect: (selected: SelectedText | null) => void): void;
|
|
23
|
+
/** Paints `range` as the held highlight while it is set, and clears it when it is not. */
|
|
24
|
+
export declare function useHeldHighlight(range: Range | null): void;
|
|
25
|
+
export interface DescribeSelectionOptions {
|
|
26
|
+
/** Elements whose text is never the page's own, such as a live demo: matched against each ancestor. */
|
|
27
|
+
ignore?: string;
|
|
28
|
+
/** How much of each part is kept, in characters: the same limits `sanitiseSelection` holds the route to, so nothing the page sends is cut again or refused. */
|
|
29
|
+
limits?: Partial<SelectionLimits>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What a highlight is about, read from the page's structure: a heading
|
|
33
|
+
* brings its section, words in a paragraph the paragraph and the heading
|
|
34
|
+
* above, a piece of a code block the whole example, and a table cell its column's
|
|
35
|
+
* header and its row (named by its first cell with words and no control).
|
|
36
|
+
* The nearest `data-chat-source` rides along as `source`, and words outside
|
|
37
|
+
* any paragraph bring that element's whole text. Text under `ignore` never counts as the page's. Each part is
|
|
38
|
+
* capped to `limits` (`DEFAULT_SELECTION_LIMITS` by default), so a select-all of a long page still fits a request.
|
|
39
|
+
*/
|
|
40
|
+
export declare function describeSelection(selected: SelectedText, root: Element, { ignore, limits }?: DescribeSelectionOptions): ChatSelection;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { DEFAULT_SELECTION_LIMITS } from "./selectionContext.js";
|
|
4
|
+
import "./selection.css";
|
|
5
|
+
const CHAT_SOURCE_ATTRIBUTE = "data-chat-source";
|
|
6
|
+
const HELD_HIGHLIGHT_NAME = "ds-chat-focus";
|
|
7
|
+
const ICON_SELECTOR = '.material-symbols-rounded, [aria-hidden="true"]';
|
|
8
|
+
const elementOf = (node) => node instanceof Element ? node : node?.parentElement ?? null;
|
|
9
|
+
function readSelection(root) {
|
|
10
|
+
const selection = document.getSelection();
|
|
11
|
+
const anchor = elementOf(selection?.anchorNode ?? null);
|
|
12
|
+
if (!selection || !anchor || !root.contains(anchor)) return void 0;
|
|
13
|
+
if (selection.isCollapsed || !selection.rangeCount) return null;
|
|
14
|
+
const range = selection.getRangeAt(0);
|
|
15
|
+
const hidden = [...root.querySelectorAll(ICON_SELECTOR)].filter((node) => range.intersectsNode(node));
|
|
16
|
+
const words = hidden.reduce((rest, node) => rest.replace(node.textContent ?? "", " "), selection.toString());
|
|
17
|
+
const text = words.replace(/\s+/g, " ").trim();
|
|
18
|
+
const holder = elementOf(range.commonAncestorContainer);
|
|
19
|
+
if (!text || !holder) return null;
|
|
20
|
+
return { text, range: range.cloneRange(), holder };
|
|
21
|
+
}
|
|
22
|
+
function useSelectionFocus(root, onSelect) {
|
|
23
|
+
const callback = useRef(onSelect);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
callback.current = onSelect;
|
|
26
|
+
});
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const onSelectionChange = () => {
|
|
29
|
+
if (!root.current) return;
|
|
30
|
+
const selected = readSelection(root.current);
|
|
31
|
+
if (selected !== void 0) callback.current(selected);
|
|
32
|
+
};
|
|
33
|
+
document.addEventListener("selectionchange", onSelectionChange);
|
|
34
|
+
return () => document.removeEventListener("selectionchange", onSelectionChange);
|
|
35
|
+
}, [root]);
|
|
36
|
+
}
|
|
37
|
+
function useHeldHighlight(range) {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (typeof CSS === "undefined" || !("highlights" in CSS)) return;
|
|
40
|
+
if (!range || !range.startContainer.isConnected) {
|
|
41
|
+
CSS.highlights.delete(HELD_HIGHLIGHT_NAME);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
CSS.highlights.set(HELD_HIGHLIGHT_NAME, new Highlight(range));
|
|
45
|
+
return () => {
|
|
46
|
+
CSS.highlights.delete(HELD_HIGHLIGHT_NAME);
|
|
47
|
+
};
|
|
48
|
+
}, [range]);
|
|
49
|
+
}
|
|
50
|
+
const HEADINGS = "h1, h2, h3, h4, h5, h6";
|
|
51
|
+
const PROSE = "p, li, dd, blockquote, figcaption";
|
|
52
|
+
const clean = (text) => (text ?? "").replace(/\s+/g, " ").trim();
|
|
53
|
+
const wordsOf = (node) => {
|
|
54
|
+
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT);
|
|
55
|
+
let words = "";
|
|
56
|
+
for (let text = walker.nextNode(); text; text = walker.nextNode()) {
|
|
57
|
+
if (!text.parentElement?.closest(ICON_SELECTOR)) words += ` ${text.textContent ?? ""}`;
|
|
58
|
+
}
|
|
59
|
+
return clean(words);
|
|
60
|
+
};
|
|
61
|
+
const levelOf = (heading) => Number(heading.tagName.slice(1));
|
|
62
|
+
const ignored = (node, root, ignore) => Boolean(ignore && node.closest(ignore) && root.contains(node.closest(ignore)));
|
|
63
|
+
function headingAbove(node, root, ignore) {
|
|
64
|
+
let found = null;
|
|
65
|
+
for (const heading of root.querySelectorAll(HEADINGS)) {
|
|
66
|
+
if (ignored(heading, root, ignore)) continue;
|
|
67
|
+
if (heading.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING || heading.contains(node)) found = heading;
|
|
68
|
+
else break;
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
72
|
+
function sectionText(heading, root, ignore, max) {
|
|
73
|
+
const level = levelOf(heading);
|
|
74
|
+
const parts = [];
|
|
75
|
+
let started = false;
|
|
76
|
+
for (const node of root.querySelectorAll(`${HEADINGS}, ${PROSE}`)) {
|
|
77
|
+
if (node === heading) {
|
|
78
|
+
started = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!started || ignored(node, root, ignore) || node.parentElement?.closest(PROSE)) continue;
|
|
82
|
+
if (node.matches(HEADINGS) && levelOf(node) <= level) break;
|
|
83
|
+
parts.push(wordsOf(node));
|
|
84
|
+
if (parts.join("\n").length >= max) break;
|
|
85
|
+
}
|
|
86
|
+
return parts.filter(Boolean).join("\n").slice(0, max);
|
|
87
|
+
}
|
|
88
|
+
function describeSelection(selected, root, { ignore, limits } = {}) {
|
|
89
|
+
const caps = { ...DEFAULT_SELECTION_LIMITS, ...limits };
|
|
90
|
+
const read = readStructure(selected, root, ignore, caps.around);
|
|
91
|
+
const capped = { text: read.text.slice(0, caps.text), kind: read.kind };
|
|
92
|
+
for (const [key, max] of [["source", caps.label], ["heading", caps.label], ["around", caps.around], ["column", caps.label], ["row", caps.label]]) {
|
|
93
|
+
const value = read[key]?.slice(0, max);
|
|
94
|
+
if (value) capped[key] = value;
|
|
95
|
+
}
|
|
96
|
+
return capped;
|
|
97
|
+
}
|
|
98
|
+
function readStructure(selected, root, ignore, maxAround) {
|
|
99
|
+
const { text, holder } = selected;
|
|
100
|
+
const marked = holder.closest(`[${CHAT_SOURCE_ATTRIBUTE}]`);
|
|
101
|
+
const source = marked?.getAttribute(CHAT_SOURCE_ATTRIBUTE) ?? void 0;
|
|
102
|
+
const base = { text, ...source ? { source } : {} };
|
|
103
|
+
const heading = holder.closest(HEADINGS);
|
|
104
|
+
if (heading) {
|
|
105
|
+
return { ...base, kind: "heading", heading: wordsOf(heading), around: sectionText(heading, root, ignore, maxAround) || void 0 };
|
|
106
|
+
}
|
|
107
|
+
const above = headingAbove(holder, root, ignore);
|
|
108
|
+
const section = above ? { heading: wordsOf(above) } : {};
|
|
109
|
+
const example = holder.closest("pre");
|
|
110
|
+
if (example) return { ...base, ...section, kind: "code", around: wordsOf(example).slice(0, maxAround) || void 0 };
|
|
111
|
+
const cell = holder.closest("td, th");
|
|
112
|
+
const row = cell?.closest("tr");
|
|
113
|
+
if (cell && row) {
|
|
114
|
+
const table = row.closest("table");
|
|
115
|
+
const index = [...row.children].indexOf(cell);
|
|
116
|
+
const header = table?.querySelector("thead tr")?.children[index];
|
|
117
|
+
const first = [...row.children].find((node) => wordsOf(node) && !node.querySelector('input, button, [role="checkbox"]'));
|
|
118
|
+
const headers = [...table?.querySelector("thead tr")?.children ?? []].map((node) => wordsOf(node));
|
|
119
|
+
const whole = [...row.children].map((node, at) => headers[at] ? `${headers[at]}: ${wordsOf(node)}` : wordsOf(node)).join("; ");
|
|
120
|
+
return {
|
|
121
|
+
...base,
|
|
122
|
+
...section,
|
|
123
|
+
kind: "cell",
|
|
124
|
+
column: header && header !== cell ? wordsOf(header) || void 0 : void 0,
|
|
125
|
+
row: first && first !== cell ? wordsOf(first) || void 0 : void 0,
|
|
126
|
+
around: whole.slice(0, maxAround) || void 0
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const paragraph = holder.closest(PROSE) ?? marked;
|
|
130
|
+
const words = paragraph && !ignored(paragraph, root, ignore) ? wordsOf(paragraph) : "";
|
|
131
|
+
return { ...base, ...section, kind: "prose", around: words && words !== text ? words.slice(0, maxAround) : void 0 };
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
CHAT_SOURCE_ATTRIBUTE,
|
|
135
|
+
HELD_HIGHLIGHT_NAME,
|
|
136
|
+
describeSelection,
|
|
137
|
+
readSelection,
|
|
138
|
+
useHeldHighlight,
|
|
139
|
+
useSelectionFocus
|
|
140
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a highlight is about, as the page reads it and the route checks it.
|
|
3
|
+
*
|
|
4
|
+
* A word alone rarely says enough ("Live", "the model picker", a token in a
|
|
5
|
+
* code line), so a highlight travels with what it sits in, read from the
|
|
6
|
+
* page's own structure by `describeSelection` (rift-ds/chat):
|
|
7
|
+
*
|
|
8
|
+
* - `heading`: a heading stands for its section, so `around` is the
|
|
9
|
+
* section's text.
|
|
10
|
+
* - `prose`: words inside a paragraph or list item bring the paragraph as
|
|
11
|
+
* `around` (outside one, the whole element a `data-chat-source` marks),
|
|
12
|
+
* and `heading` names the section above.
|
|
13
|
+
* - `code`: a piece of a code example brings the whole example.
|
|
14
|
+
* - `cell`: a table cell brings its column's header (`column`), the row's
|
|
15
|
+
* first cell (`row`) and the whole row as `around`.
|
|
16
|
+
*
|
|
17
|
+
* `source` is the nearest `data-chat-source` the host set, which says what
|
|
18
|
+
* the element is in the host's own terms ("props:Button", "kpi:revenue") and
|
|
19
|
+
* outranks anything read from structure.
|
|
20
|
+
*
|
|
21
|
+
* The route treats all of it as untrusted input: `sanitiseSelection` keeps
|
|
22
|
+
* the known fields, strips control characters and caps each, and
|
|
23
|
+
* `selectionLines` writes it for a system block, quoting every word the page
|
|
24
|
+
* sent and naming each part as the host's own text or the reader's selection
|
|
25
|
+
* through `isPublished`, the host's check against what it published. A host
|
|
26
|
+
* that cannot check says nothing is published, and every part is quoted as
|
|
27
|
+
* the reader's, never as instructions. Pure and framework-free: exported from
|
|
28
|
+
* rift-ds/chat for the page and rift-ds/chat/server for the route.
|
|
29
|
+
*/
|
|
30
|
+
/** The kinds of thing a highlight can be, read from the page's structure. */
|
|
31
|
+
export type SelectionKind = 'prose' | 'heading' | 'code' | 'cell';
|
|
32
|
+
/** A highlight and what it sits in. */
|
|
33
|
+
export interface ChatSelection {
|
|
34
|
+
/** The highlighted words. */
|
|
35
|
+
text: string;
|
|
36
|
+
/** What the highlight is, read from the page's structure. */
|
|
37
|
+
kind: SelectionKind;
|
|
38
|
+
/** The nearest `data-chat-source`: what the host says the element is. */
|
|
39
|
+
source?: string;
|
|
40
|
+
/** For a heading, the heading itself; otherwise the heading of the section it sits in. */
|
|
41
|
+
heading?: string;
|
|
42
|
+
/** What it sits in: the section's text, the paragraph, the code example, or the row. */
|
|
43
|
+
around?: string;
|
|
44
|
+
/** For a cell, its column's header. */
|
|
45
|
+
column?: string;
|
|
46
|
+
/** For a cell, the first cell of its row, which usually names the row. */
|
|
47
|
+
row?: string;
|
|
48
|
+
}
|
|
49
|
+
/** How much of each part survives, in characters. */
|
|
50
|
+
export interface SelectionLimits {
|
|
51
|
+
text: number;
|
|
52
|
+
around: number;
|
|
53
|
+
/** A heading, a source, a column or a row. */
|
|
54
|
+
label: number;
|
|
55
|
+
}
|
|
56
|
+
export declare const DEFAULT_SELECTION_LIMITS: SelectionLimits;
|
|
57
|
+
/** Checks a selection the browser sent: the known fields only, each cleaned and capped, or null. */
|
|
58
|
+
export declare function sanitiseSelection(value: unknown, limits?: Partial<SelectionLimits>): ChatSelection | null;
|
|
59
|
+
export interface SelectionLinesOptions {
|
|
60
|
+
/** Whether words are the host's own published text. Defaults to never: every part is the reader's. */
|
|
61
|
+
isPublished?: (text: string) => boolean;
|
|
62
|
+
/** What the reader is looking at, for the opening line: "the page /docs", "the orders table". */
|
|
63
|
+
where?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The selection, written for a system block: what was highlighted, what it
|
|
67
|
+
* sits in, and whether each part is the host's own words or the reader's
|
|
68
|
+
* selection. Every word the page sent is quoted.
|
|
69
|
+
*/
|
|
70
|
+
export declare function selectionLines(selection: ChatSelection, { isPublished, where }?: SelectionLinesOptions): string[];
|