rift-ds 1.30.0 → 1.32.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 +6 -4
- package/behaviors/chat-card.css +4 -1
- package/behaviors/deferComponent.d.ts +43 -0
- package/behaviors/deferComponent.js +35 -0
- package/behaviors/locale.d.ts +7 -0
- package/behaviors/locale.js +5 -0
- package/behaviors/shell.css +33 -0
- package/bin/rift-ds.mjs +35 -9
- package/bin/templates/blocks/app/planner/PlannerGrid.tsx +58 -0
- package/bin/templates/blocks/app/planner/Requests.tsx +42 -0
- package/bin/templates/blocks/app/planner/page.module.css +17 -0
- package/bin/templates/blocks/app/planner/page.tsx +32 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +10 -1
- package/bin/templates/blocks/registry.json +14 -0
- package/bin/templates/chat/app/api/chat/route.actions.ts +108 -0
- package/bin/templates/chat/components/chat/ChatMount.actions.tsx +55 -0
- package/bin/templates/chat/components/chat/ChatMount.tsx +14 -1
- package/bin/templates/chat/components/chat/proposals/ProposalCard.tsx +81 -0
- package/bin/templates/chat/components/chat/proposals/actions.ts +60 -0
- package/bin/templates/chat/components/chat/proposals/confirmation.ts +9 -0
- package/bin/templates/chat/components/chat/proposals/renderers.tsx +9 -0
- package/chat/ChatLauncher.d.ts +13 -2
- package/chat/ChatLauncher.js +52 -29
- package/chat/ChatProvider.d.ts +19 -2
- package/chat/ChatProvider.js +26 -3
- package/chat/ChatWidget.css +23 -4
- package/chat/ChatWidget.d.ts +2 -1
- package/chat/ChatWidget.js +23 -21
- package/chat/actions.d.ts +52 -6
- package/chat/actions.js +53 -5
- package/chat/contextSchema.d.ts +76 -0
- package/chat/contextSchema.js +58 -0
- package/chat/deferredChatWidget.d.ts +10 -0
- package/chat/deferredChatWidget.js +10 -0
- package/chat/index.d.ts +3 -2
- package/chat/index.js +7 -1
- package/chat/registry.json.d.ts +4 -3
- package/chat/registry.json.js +1 -1
- package/chat/server.d.ts +18 -2
- package/chat/server.js +10 -1
- package/chat/suggestions.d.ts +7 -0
- package/chat/suggestions.js +13 -1
- package/chat/types.d.ts +23 -0
- package/chat/useChat.d.ts +2 -2
- package/chat/useChat.js +15 -1
- package/components/Accordion/Accordion.css +8 -0
- package/components/AgentPlan/AgentPlan.css +8 -0
- package/components/AgentRail/AgentRail.css +3 -3
- package/components/AiButton/AiButton.css +19 -0
- package/components/AiButton/AiButton.d.ts +10 -1
- package/components/AiButton/AiButton.js +6 -1
- package/components/AppSidebar/AppSidebar.css +12 -0
- package/components/ArtifactPanel/ArtifactPanel.js +5 -5
- package/components/Attachment/AttachmentViewer.js +7 -7
- package/components/BentoTile/BentoTile.css +1 -1
- package/components/BentoTile/BentoTile.js +5 -5
- package/components/Button/Button.css +28 -1
- package/components/Button/Button.d.ts +7 -2
- package/components/Button/Button.js +7 -3
- package/components/ButtonGroup/ButtonGroup.css +10 -1
- package/components/Chart/RadarChart.js +24 -10
- package/components/ChatHeader/ChatHeader.d.ts +1 -1
- package/components/ChatThread/ChatThread.css +1 -1
- package/components/Chip/Chip.css +26 -0
- package/components/CircularButton/CircularButton.d.ts +16 -96
- package/components/CircularButton/CircularButton.js +11 -94
- package/components/Combobox/Combobox.css +12 -0
- package/components/CommandPalette/CommandPalette.css +1 -1
- package/components/CommandPalette/CommandPalette.js +3 -3
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.css +9 -0
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.d.ts +10 -2
- package/components/CommandPaletteTrigger/CommandPaletteTrigger.js +7 -2
- package/components/Composer/Composer.css +3 -3
- package/components/Composer/Composer.js +9 -9
- package/components/ContextMenu/ContextMenu.css +24 -0
- package/components/DataTable/DataTable.css +19 -4
- package/components/DataTable/DataTable.d.ts +14 -2
- package/components/DataTable/DataTable.js +28 -17
- package/components/DataTable/periodColumns.d.ts +37 -0
- package/components/DataTable/periodColumns.js +48 -0
- package/components/DateInput/DateInput.css +20 -0
- package/components/DatePicker/DatePicker.css +22 -6
- package/components/DatePicker/DatePicker.d.ts +2 -1
- package/components/DatePicker/DatePicker.js +2 -2
- package/components/DateRangePicker/DateRangePicker.js +2 -2
- package/components/DecisionRow/DecisionRow.css +46 -0
- package/components/DecisionRow/DecisionRow.d.ts +62 -0
- package/components/DecisionRow/DecisionRow.js +93 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +1 -1
- package/components/DescriptionList/DescriptionListCopy.js +3 -3
- package/components/Dialog/Dialog.css +1 -1
- package/components/Dialog/Dialog.js +3 -3
- package/components/DocumentChip/DocumentChip.css +12 -0
- package/components/DocumentViewer/DocumentViewer.js +10 -10
- package/components/Drawer/Drawer.css +1 -1
- package/components/Drawer/Drawer.js +3 -3
- package/components/Dropdown/Dropdown.css +30 -0
- package/components/DropdownMenu/DropdownMenu.css +24 -0
- package/components/EventCalendar/EventCalendar.css +54 -0
- package/components/EventCalendar/EventCalendar.d.ts +27 -5
- package/components/EventCalendar/EventCalendar.js +50 -15
- package/components/FileInput/FileInput.css +9 -0
- package/components/FilterBar/FilterBar.css +12 -0
- package/components/FunnelChart/FunnelChart.js +33 -22
- package/components/Globe/Globe.css +7 -0
- package/components/Globe/Globe.js +1 -1
- package/components/{CircularButton/CircularButton.css → IconButton/IconButton.css} +91 -81
- package/components/IconButton/IconButton.d.ts +108 -0
- package/components/IconButton/IconButton.js +101 -0
- package/components/Input/Input.css +53 -0
- package/components/Input/Input.js +3 -3
- package/components/MaskedInput/MaskedInput.js +3 -3
- package/components/ModelPicker/ModelPicker.css +12 -1
- package/components/NavList/NavList.css +1 -1
- package/components/Pagination/Pagination.css +1 -1
- package/components/QuestionCard/QuestionCard.js +3 -3
- package/components/RadioButton/RadioButton.css +14 -12
- package/components/RichDropdown/RichDropdown.css +7 -0
- package/components/SegmentedControl/SegmentedControl.css +16 -5
- package/components/SegmentedControl/SegmentedControl.js +7 -4
- package/components/SiteHeader/SiteHeader.css +12 -5
- package/components/SiteHeader/SiteHeader.js +3 -3
- package/components/SourceTrail/SourceTrail.css +8 -0
- package/components/SplitButton/SplitButton.css +14 -14
- package/components/SplitButton/SplitButton.js +3 -3
- package/components/Table/Table.css +7 -0
- package/components/Table/Table.js +1 -1
- package/components/TableToolbar/TableToolbar.css +2 -2
- package/components/TableToolbar/TableToolbar.js +36 -37
- package/components/Tabs/Tabs.css +21 -3
- package/components/ThreadPanel/ThreadPanel.css +8 -0
- package/components/ThreadTabs/ThreadTabs.css +7 -0
- package/components/TimePicker/TimePicker.css +12 -0
- package/components/Timeline/Timeline.css +8 -0
- package/components/ToolCall/ToolCall.css +8 -0
- package/components/Tooltip/Tooltip.js +3 -2
- package/components/Widget/Widget.css +2 -0
- package/components/WorldMap/WorldMap.css +15 -0
- package/components/WorldMap/WorldMap.js +61 -6
- package/components/registry.d.ts +3 -1
- package/components/registry.json +39 -13
- package/components/registry.json.d.ts +39 -13
- package/components/registry.json.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +8 -0
- package/package.json +6 -2
- package/tokens/presets/blueprint.css +9 -0
- package/tokens/presets/bubblegum.css +9 -0
- package/tokens/presets/contrast.css +3 -3
- package/tokens/presets/coral.css +3 -3
- package/tokens/presets/ember.css +9 -0
- package/tokens/presets/getaway.css +9 -0
- package/tokens/presets/gold.css +3 -3
- package/tokens/presets/mono.css +3 -3
- package/tokens/presets/pink.css +3 -3
- package/tokens/presets/plum.css +3 -3
- package/tokens/presets/signal.css +9 -0
- package/tokens/presets/smoke.css +9 -0
- package/tokens/presets/velvet.css +9 -0
- package/tokens/presets/violet.css +3 -3
- package/tokens/presets/volt.css +9 -0
- package/tokens/presets/warm.css +3 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The chat, mounted once, with the propose-and-confirm flow wired in.
|
|
5
|
+
* Render <ChatMount /> at the end of your root layout's body, after the page
|
|
6
|
+
* content, so the panel sits last in the tab order and survives client-side
|
|
7
|
+
* navigation. It posts to /api/chat: set ANTHROPIC_API_KEY and
|
|
8
|
+
* CHAT_ENABLED=true in .env.local.
|
|
9
|
+
*
|
|
10
|
+
* Each request carries the page's path and, once, the confirmation a card's
|
|
11
|
+
* Confirm marked (proposals/confirmation.ts), which the route rebuilds as untrusted
|
|
12
|
+
* input. The cards are drawn by ACTION_RENDERERS.
|
|
13
|
+
*/
|
|
14
|
+
import { useCallback } from 'react';
|
|
15
|
+
import { usePathname } from 'next/navigation';
|
|
16
|
+
import { ChatLauncher, ChatProvider } from 'rift-ds/chat';
|
|
17
|
+
import 'rift-ds/chat/chat.css';
|
|
18
|
+
import { CHAT_MODELS, DEFAULT_CHAT_MODEL } from './models';
|
|
19
|
+
import { confirmation } from './proposals/confirmation';
|
|
20
|
+
import { ACTION_RENDERERS } from './proposals/renderers';
|
|
21
|
+
|
|
22
|
+
/** What the widget says about itself. Edit freely. */
|
|
23
|
+
const WIDGET = {
|
|
24
|
+
title: 'Assistant',
|
|
25
|
+
tagline: 'What should change?',
|
|
26
|
+
/* Each starter is one chip, and a chip never wraps: a label longer than 30
|
|
27
|
+
characters (SUGGESTION_MAX_CHARS) is dropped, with a warning in
|
|
28
|
+
development. Write a month or weekday short ("Oct", "Mon"). */
|
|
29
|
+
starters: [
|
|
30
|
+
{ id: 'open', label: 'What is still open?' },
|
|
31
|
+
{ id: 'done', label: 'Mark the open items done' },
|
|
32
|
+
{ id: 'tidy', label: 'Archive what is done' },
|
|
33
|
+
],
|
|
34
|
+
models: CHAT_MODELS,
|
|
35
|
+
defaultModel: DEFAULT_CHAT_MODEL,
|
|
36
|
+
disclaimer: 'Answers may be wrong. Changes wait for your Confirm.',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function ChatMount() {
|
|
40
|
+
const pathname = usePathname();
|
|
41
|
+
/* The note over the composer says what the chat is looking at. */
|
|
42
|
+
const context = { label: pathname === '/' ? 'Home' : pathname };
|
|
43
|
+
/* Read at each send, so the mark is taken by the one request it belongs
|
|
44
|
+
to. A stable function: a new one would make a new transport. */
|
|
45
|
+
const getContext = useCallback(
|
|
46
|
+
() => JSON.stringify({ path: window.location.pathname, confirmation: confirmation.take() }),
|
|
47
|
+
[]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ChatProvider getContext={getContext} renderers={ACTION_RENDERERS} followups="/api/chat/followups" feedback="/api/chat/feedback">
|
|
52
|
+
<ChatLauncher label={`Ask ${WIDGET.title}`} widget={{ ...WIDGET, context }} />
|
|
53
|
+
</ChatProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* peer for its chart cards. Once you are live for good, delete the demo
|
|
16
16
|
* import and the peer with it.
|
|
17
17
|
*/
|
|
18
|
+
import { usePathname } from 'next/navigation';
|
|
18
19
|
import { ChatLauncher, ChatProvider } from 'rift-ds/chat';
|
|
19
20
|
import { DEMO_RENDERERS, DEMO_STARTERS, createDemoTransport } from 'rift-ds/chat/demo';
|
|
20
21
|
import 'rift-ds/chat/chat.css';
|
|
@@ -26,6 +27,9 @@ const DEMO = process.env.NEXT_PUBLIC_CHAT_DEMO === 'true';
|
|
|
26
27
|
const WIDGET = {
|
|
27
28
|
title: 'Assistant',
|
|
28
29
|
tagline: 'How can I help you today?',
|
|
30
|
+
/* Each starter is one chip, and a chip never wraps: a label longer than 30
|
|
31
|
+
characters (SUGGESTION_MAX_CHARS) is dropped, with a warning in
|
|
32
|
+
development. Write a month or weekday short ("Oct", "Mon"). */
|
|
29
33
|
starters: DEMO
|
|
30
34
|
? DEMO_STARTERS
|
|
31
35
|
: [
|
|
@@ -39,6 +43,15 @@ const WIDGET = {
|
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
export function ChatMount() {
|
|
46
|
+
/* The note over the composer says what the chat is looking at. Here it is
|
|
47
|
+
the page; a host whose chat follows more (a highlighted passage, the
|
|
48
|
+
rows ticked in a table) names that instead, and sends the same through
|
|
49
|
+
ChatProvider's getContext. useSelectionFocus and useHeldHighlight, from
|
|
50
|
+
rift-ds/chat, follow a highlight and keep it painted while the reader
|
|
51
|
+
types. */
|
|
52
|
+
const pathname = usePathname();
|
|
53
|
+
const context = { label: pathname === '/' ? 'Home' : pathname };
|
|
54
|
+
|
|
42
55
|
return (
|
|
43
56
|
<ChatProvider
|
|
44
57
|
transport={DEMO ? createDemoTransport() : undefined}
|
|
@@ -46,7 +59,7 @@ export function ChatMount() {
|
|
|
46
59
|
followups={DEMO ? false : '/api/chat/followups'}
|
|
47
60
|
feedback={DEMO ? false : '/api/chat/feedback'}
|
|
48
61
|
>
|
|
49
|
-
<ChatLauncher label={`Ask ${WIDGET.title}`} widget={WIDGET} />
|
|
62
|
+
<ChatLauncher label={`Ask ${WIDGET.title}`} widget={{ ...WIDGET, context }} />
|
|
50
63
|
</ChatProvider>
|
|
51
64
|
);
|
|
52
65
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The cards of the propose-and-confirm flow, as the chat's renderers.
|
|
5
|
+
*
|
|
6
|
+
* `proposal` is a change the assistant planned: an ActionCard with Confirm
|
|
7
|
+
* and Cancel. Confirm runs the action on the page (`applyPlan`, yours to
|
|
8
|
+
* write), marks the request it sends so the route knows this message was
|
|
9
|
+
* confirmed on its card (a typed "yes" never is), and sends the reader's
|
|
10
|
+
* words as their message. The card then settles to one row.
|
|
11
|
+
*
|
|
12
|
+
* `record` is what was done, which the route sends as the reply's lead card:
|
|
13
|
+
* the same ActionCard, confirmed. Each card's state is kept by its id outside
|
|
14
|
+
* React, so a redraw or a reopened panel never offers Confirm again.
|
|
15
|
+
* renderers.tsx hands both to the chat.
|
|
16
|
+
*/
|
|
17
|
+
import { useSyncExternalStore } from 'react';
|
|
18
|
+
import { ActionCard } from 'rift-ds/components/ActionCard/ActionCard';
|
|
19
|
+
import { skippedText, type ActionPlan } from 'rift-ds/chat/actions';
|
|
20
|
+
import { useChatWidget } from 'rift-ds/chat';
|
|
21
|
+
import { ACTIONS, theseItems, type ActionId } from './actions';
|
|
22
|
+
import { confirmation } from './confirmation';
|
|
23
|
+
|
|
24
|
+
/** Apply a confirmed plan to your page's data. Replace this with your own write. */
|
|
25
|
+
function applyPlan(plan: ActionPlan) {
|
|
26
|
+
console.info('Apply', plan.action, 'to', plan.ids);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type CardStatus = 'proposed' | 'confirmed' | 'dismissed';
|
|
30
|
+
const statuses = new Map<string, CardStatus>();
|
|
31
|
+
const listeners = new Set<() => void>();
|
|
32
|
+
const setStatus = (id: string, status: CardStatus) => {
|
|
33
|
+
statuses.set(id, status);
|
|
34
|
+
listeners.forEach((listener) => listener());
|
|
35
|
+
};
|
|
36
|
+
const subscribe = (listener: () => void) => {
|
|
37
|
+
listeners.add(listener);
|
|
38
|
+
return () => listeners.delete(listener);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type ProposalData = ActionPlan & { id: string };
|
|
42
|
+
|
|
43
|
+
export function Proposal({ id, action, ids, skipped }: ProposalData) {
|
|
44
|
+
const { send, streaming } = useChatWidget();
|
|
45
|
+
const status = useSyncExternalStore<CardStatus>(subscribe, () => statuses.get(id) ?? 'proposed', () => 'proposed');
|
|
46
|
+
const definition = ACTIONS[action as ActionId];
|
|
47
|
+
if (!definition) return null;
|
|
48
|
+
const left = skippedText(skipped);
|
|
49
|
+
return (
|
|
50
|
+
<ActionCard
|
|
51
|
+
title={`${definition.label}: ${ids.length} ${ids.length === 1 ? 'item' : 'items'}`}
|
|
52
|
+
detail={[definition.effect?.(ids.length), left && `Left alone: ${left}.`].filter(Boolean).join(' ')}
|
|
53
|
+
icon={definition.icon}
|
|
54
|
+
tone={definition.destructive ? 'destructive' : 'default'}
|
|
55
|
+
status={status}
|
|
56
|
+
onConfirm={
|
|
57
|
+
streaming
|
|
58
|
+
? undefined
|
|
59
|
+
: () => {
|
|
60
|
+
applyPlan({ action, ids, skipped });
|
|
61
|
+
setStatus(id, 'confirmed');
|
|
62
|
+
confirmation.mark({ action: action as ActionId, count: ids.length, ids });
|
|
63
|
+
send(definition.confirm(theseItems(ids.length)));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onDismiss={() => setStatus(id, 'dismissed')}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function RecordCard({ action, count }: { action: string; count: number }) {
|
|
72
|
+
const definition = ACTIONS[action as ActionId];
|
|
73
|
+
if (!definition) return null;
|
|
74
|
+
return (
|
|
75
|
+
<ActionCard
|
|
76
|
+
title={`${count} ${count === 1 ? 'item' : 'items'} ${definition.done}`}
|
|
77
|
+
icon={definition.icon}
|
|
78
|
+
status="confirmed"
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The changes the chat may propose, defined once for the page and the route.
|
|
3
|
+
*
|
|
4
|
+
* A chat proposes and the reader confirms: the route's tool plans an action
|
|
5
|
+
* over the records the request means and sends the plan as a card; the card
|
|
6
|
+
* (ProposalCard.tsx) runs it on the reader's Confirm and sends their words as
|
|
7
|
+
* their message; the route opens the reply with the record of what was done.
|
|
8
|
+
* The page's own buttons should run these same actions, so the chat and the
|
|
9
|
+
* page can never do different things to the same records.
|
|
10
|
+
*
|
|
11
|
+
* Replace the records and the actions with your own. This module imports
|
|
12
|
+
* nothing but rift-ds/chat/actions, so the route and the browser can both
|
|
13
|
+
* import it.
|
|
14
|
+
*/
|
|
15
|
+
import { defineAction } from 'rift-ds/chat/actions';
|
|
16
|
+
|
|
17
|
+
/** One record the actions act on. Yours will have more fields. */
|
|
18
|
+
export type Item = { title: string; state: 'open' | 'done' | 'archived' };
|
|
19
|
+
|
|
20
|
+
export const ACTIONS = {
|
|
21
|
+
complete: defineAction<Item>({
|
|
22
|
+
id: 'complete',
|
|
23
|
+
label: 'Mark done',
|
|
24
|
+
done: 'marked done',
|
|
25
|
+
confirm: (these) => `Mark ${these} done`,
|
|
26
|
+
effect: (count) => (count === 1 ? 'It moves to done.' : 'They move to done.'),
|
|
27
|
+
icon: 'check_circle',
|
|
28
|
+
skip: (item) => (item.state === 'open' ? null : 'not open'),
|
|
29
|
+
apply: () => ({ state: 'done' }),
|
|
30
|
+
}),
|
|
31
|
+
archive: defineAction<Item>({
|
|
32
|
+
id: 'archive',
|
|
33
|
+
label: 'Archive',
|
|
34
|
+
done: 'archived',
|
|
35
|
+
confirm: (these) => `Archive ${these}`,
|
|
36
|
+
effect: (count) => (count === 1 ? 'It leaves the list.' : 'They leave the list.'),
|
|
37
|
+
icon: 'archive',
|
|
38
|
+
destructive: true,
|
|
39
|
+
skip: (item) => (item.state === 'done' ? null : 'not done'),
|
|
40
|
+
apply: () => ({ state: 'archived' }),
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type ActionId = keyof typeof ACTIONS;
|
|
45
|
+
|
|
46
|
+
/** "this item" or "these 3 items", for the reader's confirming words. */
|
|
47
|
+
export const theseItems = (count: number) => (count === 1 ? 'this item' : `these ${count} items`);
|
|
48
|
+
|
|
49
|
+
/** The noun after a count, for the line that tells the model what was confirmed. */
|
|
50
|
+
export const itemNoun = (count: number) => (count === 1 ? 'item' : 'items');
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Sample records, so the example runs. Replace with a read of your own
|
|
54
|
+
* data: the route plans against it, and the page applies to it.
|
|
55
|
+
*/
|
|
56
|
+
export const SAMPLE_ITEMS: Record<string, Item> = {
|
|
57
|
+
'item-1': { title: 'Write the brief', state: 'open' },
|
|
58
|
+
'item-2': { title: 'Book the venue', state: 'done' },
|
|
59
|
+
'item-3': { title: 'Send the invites', state: 'open' },
|
|
60
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's one-shot confirmation mark: a card's Confirm sets it, and the
|
|
3
|
+
* next request's context takes it, once. ChatMount's getContext reads it;
|
|
4
|
+
* the route rebuilds it as untrusted input, so a typed "yes" never counts.
|
|
5
|
+
*/
|
|
6
|
+
import { createConfirmationMark } from 'rift-ds/chat/actions';
|
|
7
|
+
import type { ActionId } from './actions';
|
|
8
|
+
|
|
9
|
+
export const confirmation = createConfirmationMark<ActionId>();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/** The chat's card renderers, by kind: pass to ChatProvider's `renderers`. */
|
|
4
|
+
import { Proposal, RecordCard, type ProposalData } from './ProposalCard';
|
|
5
|
+
|
|
6
|
+
export const ACTION_RENDERERS = {
|
|
7
|
+
proposal: (data: unknown) => <Proposal {...(data as ProposalData)} />,
|
|
8
|
+
record: (data: unknown) => <RecordCard {...(data as { action: string; count: number })} />,
|
|
9
|
+
};
|
package/chat/ChatLauncher.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface ChatLauncherProps {
|
|
|
34
34
|
* the chat from a control of its own, such as an AiButton in its top bar:
|
|
35
35
|
* that control calls `setOpen(true)` from `useChatWidget()` and sets
|
|
36
36
|
* `returnFocusRef.current` to itself, so closing the panel hands focus back.
|
|
37
|
+
* It also calls `preloadChatWidget` on hover and focus, as the floating
|
|
38
|
+
* button does.
|
|
37
39
|
*/
|
|
38
40
|
fab?: boolean;
|
|
39
41
|
/** The panel's DOM id, for a host control's `aria-controls`. */
|
|
@@ -48,6 +50,12 @@ export interface ChatLauncherProps {
|
|
|
48
50
|
panelLabel?: string;
|
|
49
51
|
/** The words of the floating button's summary panel, over AiButton's English defaults: the panel's name, given the summary's title ("Summary: <title>"), its dismiss button ("Dismiss summary") and its chips' group ("Suggested prompts"). */
|
|
50
52
|
aiButtonLabels?: Pick<AiButtonProps, 'summaryRegionLabel' | 'dismissLabel' | 'suggestionsLabel'>;
|
|
53
|
+
/**
|
|
54
|
+
* Accessible name of the spinner the panel shows while the chat's code is
|
|
55
|
+
* still arriving: the panel was opened before the preload finished, or the
|
|
56
|
+
* visitor asked to save data and nothing was preloaded.
|
|
57
|
+
*/
|
|
58
|
+
loadingLabel?: string;
|
|
51
59
|
/** Everything the widget takes. The launcher sets the responsive ones itself. */
|
|
52
60
|
widget?: Omit<ChatWidgetProps, 'fullscreenEnabled' | 'placementEnabled' | 'compact' | 'phone'>;
|
|
53
61
|
/** Rendered inside the panel after the widget: for a host's extra chrome. */
|
|
@@ -83,7 +91,10 @@ export interface ChatLauncherProps {
|
|
|
83
91
|
* writes the chosen dock width to `--ds-chat-width` there; a host's
|
|
84
92
|
* stylesheet pads the page beside a docked panel and hides it behind a
|
|
85
93
|
* takeover from those two facts (the package's own stylesheet does not
|
|
86
|
-
* touch the host's body).
|
|
94
|
+
* touch the host's body). An app shell needs no rule of its own: the shell
|
|
95
|
+
* recipe (src/behaviors/shell.css) gives the outermost `data-ds-shell` host,
|
|
96
|
+
* AppLayout and the app-shell block among them, the panel's width plus its
|
|
97
|
+
* edge gap on the docked side. The panel's geometry reads `--ds-chat-width`,
|
|
87
98
|
* `--ds-chat-inset` and `--ds-chat-float-height`, defaulted on `:root`.
|
|
88
99
|
*/
|
|
89
|
-
export declare function ChatLauncher({ label, icon, summary, hidden, panelId, hostAttribute, panelLabel, aiButtonLabels, widget, children, surface, fab, }: ChatLauncherProps): import("react").JSX.Element | null;
|
|
100
|
+
export declare function ChatLauncher({ label, icon, summary, hidden, panelId, hostAttribute, panelLabel, aiButtonLabels, loadingLabel, widget, children, surface, fab, }: ChatLauncherProps): import("react").JSX.Element | null;
|
package/chat/ChatLauncher.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useSyncExternalStore, useLayoutEffect, useRef, useEffect, useState } from "react";
|
|
3
|
+
import { useSyncExternalStore, useLayoutEffect, useRef, useEffect, useState, Suspense } from "react";
|
|
4
|
+
import { usePreloadWhenIdle } from "../behaviors/deferComponent.js";
|
|
4
5
|
import { useScrollLock } from "../behaviors/useScrollLock.js";
|
|
5
6
|
import { AiButton } from "../components/AiButton/AiButton.js";
|
|
6
|
-
import {
|
|
7
|
+
import { Spinner } from "../components/Spinner/Spinner.js";
|
|
7
8
|
import { useChatAgentState } from "./agentState.js";
|
|
8
9
|
import { useChatWidget } from "./context.js";
|
|
10
|
+
import { DeferredChatWidget } from "./deferredChatWidget.js";
|
|
9
11
|
import { isFloatDragStart, FLOAT_EDGE_GAP, FLOAT_MAX_SCALE, dockWidthFromDrag, clampFloatPosition } from "./placement.js";
|
|
10
12
|
import { useDockViewport, TAKEOVER_QUERY } from "./queries.js";
|
|
13
|
+
import { keepFittingSuggestions } from "./suggestions.js";
|
|
11
14
|
import "./ChatWidget.css";
|
|
12
15
|
const CHAT_PANEL_ID = "ds-chat-panel";
|
|
13
16
|
const FLOAT_GRIPS = [
|
|
@@ -42,6 +45,7 @@ function ChatLauncher({
|
|
|
42
45
|
hostAttribute = "data-chat",
|
|
43
46
|
panelLabel = "Chat",
|
|
44
47
|
aiButtonLabels,
|
|
48
|
+
loadingLabel = "Loading chat",
|
|
45
49
|
widget,
|
|
46
50
|
children,
|
|
47
51
|
surface = "raised",
|
|
@@ -49,6 +53,7 @@ function ChatLauncher({
|
|
|
49
53
|
}) {
|
|
50
54
|
const { open, setOpen, panelPhase, view, side, floating, returnFocusRef, send } = useChatWidget();
|
|
51
55
|
const agentState = useChatAgentState();
|
|
56
|
+
usePreloadWhenIdle(DeferredChatWidget.preload);
|
|
52
57
|
const launchSuggestion = (id) => {
|
|
53
58
|
const chip = summary?.chips?.find((c) => c.id === id);
|
|
54
59
|
if (!chip) return;
|
|
@@ -247,29 +252,41 @@ function ChatLauncher({
|
|
|
247
252
|
if (hidden) return null;
|
|
248
253
|
if (!renderPanel) {
|
|
249
254
|
if (!fab) return null;
|
|
250
|
-
return /* @__PURE__ */ jsx(
|
|
251
|
-
|
|
255
|
+
return /* @__PURE__ */ jsx(
|
|
256
|
+
"div",
|
|
252
257
|
{
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
258
|
+
className: "ds-chat-launcher__fab",
|
|
259
|
+
onPointerEnter: DeferredChatWidget.preload,
|
|
260
|
+
onFocusCapture: DeferredChatWidget.preload,
|
|
261
|
+
children: /* @__PURE__ */ jsx(
|
|
262
|
+
AiButton,
|
|
263
|
+
{
|
|
264
|
+
...aiButtonLabels,
|
|
265
|
+
label,
|
|
266
|
+
icon,
|
|
267
|
+
state: agentState,
|
|
268
|
+
"aria-expanded": false,
|
|
269
|
+
"aria-controls": panelId,
|
|
270
|
+
summary: summary ? {
|
|
271
|
+
overline: summary.overline,
|
|
272
|
+
title: summary.title,
|
|
273
|
+
caption: summary.caption,
|
|
274
|
+
text: summary.text,
|
|
275
|
+
suggestions: keepFittingSuggestions(
|
|
276
|
+
summary.suggestions ?? summary.chips?.map(({ id, label: chipLabel }) => ({ id, label: chipLabel })) ?? [],
|
|
277
|
+
(chip) => chip.label,
|
|
278
|
+
"ChatLauncher summary chips"
|
|
279
|
+
)
|
|
280
|
+
} : void 0,
|
|
281
|
+
onSummarySuggestion: launchSuggestion,
|
|
282
|
+
onClick: (event) => {
|
|
283
|
+
returnFocusRef.current = event.currentTarget;
|
|
284
|
+
setOpen(true);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
)
|
|
271
288
|
}
|
|
272
|
-
)
|
|
289
|
+
);
|
|
273
290
|
}
|
|
274
291
|
const handleKeyDown = (event) => {
|
|
275
292
|
if (event.key === "Escape") {
|
|
@@ -331,13 +348,19 @@ function ChatLauncher({
|
|
|
331
348
|
onKeyDown: handleKeyDown,
|
|
332
349
|
children: [
|
|
333
350
|
/* @__PURE__ */ jsx(
|
|
334
|
-
|
|
351
|
+
Suspense,
|
|
335
352
|
{
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
353
|
+
fallback: /* @__PURE__ */ jsx("div", { className: "ds-chat-launcher__loading", children: /* @__PURE__ */ jsx(Spinner, { size: "lg", tone: "neutral", label: loadingLabel }) }),
|
|
354
|
+
children: /* @__PURE__ */ jsx(
|
|
355
|
+
DeferredChatWidget.Component,
|
|
356
|
+
{
|
|
357
|
+
...widget,
|
|
358
|
+
fullscreenEnabled: !takeover,
|
|
359
|
+
placementEnabled: !takeover,
|
|
360
|
+
compact: takeover || !isFull,
|
|
361
|
+
phone: takeover
|
|
362
|
+
}
|
|
363
|
+
)
|
|
341
364
|
}
|
|
342
365
|
),
|
|
343
366
|
children,
|
package/chat/ChatProvider.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ChatArtifactRenderers, ChatCardRenderers, ChatLinkRenderer, FeedbackSin
|
|
|
3
3
|
import { FollowupsSource } from './followups';
|
|
4
4
|
import { ChatPlacement } from './placement';
|
|
5
5
|
import { ThreadsOptions } from './threads';
|
|
6
|
-
import { ChatTransport } from './types';
|
|
6
|
+
import { ChatPageAction, ChatTransport } from './types';
|
|
7
7
|
import { ChatPlaceholderCopy } from './useChat';
|
|
8
8
|
export interface ChatProviderProps {
|
|
9
9
|
/**
|
|
@@ -12,6 +12,23 @@ export interface ChatProviderProps {
|
|
|
12
12
|
* `scriptChat()` runs the widget with no backend at all.
|
|
13
13
|
*/
|
|
14
14
|
transport?: ChatTransport;
|
|
15
|
+
/**
|
|
16
|
+
* Wraps the default transport instead of replacing it: handed the fetch
|
|
17
|
+
* transport, which carries the reader's model pick and `getContext`, it
|
|
18
|
+
* returns the transport the chat uses, so a host can add to the stream (a
|
|
19
|
+
* card the reply opens with, a log) and keep that wiring. Pass a stable
|
|
20
|
+
* function, declared outside the component or memoised, that reads what it
|
|
21
|
+
* needs when it runs rather than from render. Ignored with a `transport`.
|
|
22
|
+
*/
|
|
23
|
+
wrapTransport?: (base: ChatTransport) => ChatTransport;
|
|
24
|
+
/**
|
|
25
|
+
* What the page does when a reply sends an `action` event, by the action's
|
|
26
|
+
* `name`: go to a page, set a table's view, open a tab. Each runs once, as
|
|
27
|
+
* the event arrives, never again on a redraw. The input came from the model,
|
|
28
|
+
* so a handler checks it before acting on it. A name with no handler is
|
|
29
|
+
* ignored, with a warning in development.
|
|
30
|
+
*/
|
|
31
|
+
pageActions?: Record<string, (input: unknown, action: ChatPageAction) => void>;
|
|
15
32
|
/** The endpoint the default transport posts to. */
|
|
16
33
|
endpoint?: string;
|
|
17
34
|
/**
|
|
@@ -66,4 +83,4 @@ export interface ChatProviderProps {
|
|
|
66
83
|
* clicking between pages for free. A hard reload starts clean by design:
|
|
67
84
|
* no storage, no persistence.
|
|
68
85
|
*/
|
|
69
|
-
export declare function ChatProvider({ transport, endpoint, getContext, defaultPlacement, followups, fallbackFollowups, feedback, renderers, artifactRenderers, renderLink, isInternalHref, threads: threadsOptions, placeholders, children, }: ChatProviderProps): import("react").JSX.Element;
|
|
86
|
+
export declare function ChatProvider({ transport, wrapTransport, pageActions, endpoint, getContext, defaultPlacement, followups, fallbackFollowups, feedback, renderers, artifactRenderers, renderLink, isInternalHref, threads: threadsOptions, placeholders, children, }: ChatProviderProps): import("react").JSX.Element;
|
package/chat/ChatProvider.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useState, useMemo, useRef, useEffect
|
|
3
|
+
import { useState, useMemo, useCallback, useRef, useEffect } from "react";
|
|
4
4
|
import { MOTION_EXIT_SYNC_MS } from "../tokens/motion.js";
|
|
5
5
|
import { createFeedbackPoster, isInternalPath, ChatWidgetContext } from "./context.js";
|
|
6
6
|
import { createFollowupsFetcher, followupTarget, DEFAULT_FALLBACK_FOLLOWUPS, pickFallbackFollowups } from "./followups.js";
|
|
7
7
|
import { useThreads } from "./threads.js";
|
|
8
8
|
import { createFetchTransport } from "./transport.js";
|
|
9
|
+
import { keepFittingSuggestions } from "./suggestions.js";
|
|
10
|
+
import { warnOnce } from "../behaviors/devWarning.js";
|
|
9
11
|
import { DEFAULT_PLACEHOLDER_COPY, useChat } from "./useChat.js";
|
|
10
12
|
import { useLinkComponent } from "../behaviors/LinkProvider.js";
|
|
11
13
|
function DefaultChatLink({ href, children, onNavigate }) {
|
|
@@ -20,6 +22,8 @@ function DefaultChatLink({ href, children, onNavigate }) {
|
|
|
20
22
|
const defaultRenderLink = (props) => /* @__PURE__ */ jsx(DefaultChatLink, { ...props });
|
|
21
23
|
function ChatProvider({
|
|
22
24
|
transport,
|
|
25
|
+
wrapTransport,
|
|
26
|
+
pageActions,
|
|
23
27
|
endpoint = "/api/chat",
|
|
24
28
|
getContext,
|
|
25
29
|
defaultPlacement = "right",
|
|
@@ -43,7 +47,22 @@ function ChatProvider({
|
|
|
43
47
|
() => ({ ...DEFAULT_PLACEHOLDER_COPY, ...placeholders }),
|
|
44
48
|
[placeholders]
|
|
45
49
|
);
|
|
46
|
-
const
|
|
50
|
+
const wrappedTransport = useMemo(
|
|
51
|
+
() => wrapTransport ? wrapTransport(fallbackTransport) : fallbackTransport,
|
|
52
|
+
[wrapTransport, fallbackTransport]
|
|
53
|
+
);
|
|
54
|
+
const runPageAction = useCallback(
|
|
55
|
+
(action) => {
|
|
56
|
+
const handler = pageActions?.[action.name];
|
|
57
|
+
if (!handler) {
|
|
58
|
+
warnOnce(`ChatProvider: no pageActions handler named "${action.name}", so the action was ignored.`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
handler(action.input, action);
|
|
62
|
+
},
|
|
63
|
+
[pageActions]
|
|
64
|
+
);
|
|
65
|
+
const chat = useChat(transport ?? wrappedTransport, placeholderCopy, runPageAction);
|
|
47
66
|
const threads = useThreads(chat, threadsOptions);
|
|
48
67
|
const followupsSource = useMemo(() => {
|
|
49
68
|
if (followups === false) return null;
|
|
@@ -57,7 +76,11 @@ function ChatProvider({
|
|
|
57
76
|
if (!target || askedRef.current.has(target.id)) return;
|
|
58
77
|
askedRef.current.add(target.id);
|
|
59
78
|
const offer = (suggestions) => {
|
|
60
|
-
const offered = suggestions.length > 0 ? suggestions : pickFallbackFollowups(
|
|
79
|
+
const offered = suggestions.length > 0 ? suggestions : pickFallbackFollowups(
|
|
80
|
+
keepFittingSuggestions(fallbackFollowups, (label) => label, "ChatProvider fallbackFollowups"),
|
|
81
|
+
target.id,
|
|
82
|
+
target.question
|
|
83
|
+
);
|
|
61
84
|
setTurnFollowups(target.id, offered);
|
|
62
85
|
setFreshFollowupsId(target.id);
|
|
63
86
|
};
|
package/chat/ChatWidget.css
CHANGED
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
display: none;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
.ds-chat-widget__placement-menu .ds-
|
|
82
|
-
.ds-chat-widget__placement-menu .ds-
|
|
81
|
+
.ds-chat-widget__placement-menu .ds-icon-button[aria-expanded="true"],
|
|
82
|
+
.ds-chat-widget__placement-menu .ds-icon-button[aria-expanded="true"]:hover {
|
|
83
83
|
background-color: var(--color-action-passive-bg-hover);
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -329,6 +329,16 @@
|
|
|
329
329
|
flex-shrink: 0;
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
/* Widgets taller than the whole widget (a board stacked to one column in a
|
|
333
|
+
narrow panel) have no room to ride up into, so the welcome scrolls
|
|
334
|
+
rather than letting its host's edge cut the board off. While they fit
|
|
335
|
+
there is nothing to scroll, and the layout above is unchanged. */
|
|
336
|
+
.ds-chat-widget[data-widgets="fit"]:has(.ds-chat-widget__welcome) {
|
|
337
|
+
overflow-y: auto;
|
|
338
|
+
overscroll-behavior: contain;
|
|
339
|
+
scrollbar-width: thin;
|
|
340
|
+
}
|
|
341
|
+
|
|
332
342
|
/* The widgets claim their height first, so on a short window an even split
|
|
333
343
|
of what is left would crowd the greeting into the header. The top region
|
|
334
344
|
keeps room for the header and the greeting. A phone never centres, so it
|
|
@@ -1015,8 +1025,8 @@
|
|
|
1015
1025
|
/* The agent toggle's on-state: the passive wash, held down while the panel
|
|
1016
1026
|
is up. Paired with the library class so it beats the variant's resting
|
|
1017
1027
|
background whatever order the stylesheets load in. */
|
|
1018
|
-
.ds-
|
|
1019
|
-
.ds-
|
|
1028
|
+
.ds-icon-button.ds-chat-widget__agent-toggle--on,
|
|
1029
|
+
.ds-icon-button.ds-chat-widget__agent-toggle--on:hover {
|
|
1020
1030
|
background-color: var(--color-action-passive-bg-hover);
|
|
1021
1031
|
}
|
|
1022
1032
|
|
|
@@ -1066,6 +1076,15 @@
|
|
|
1066
1076
|
|
|
1067
1077
|
/* The widen grip drives --ds-chat-width frame by frame; the width glide
|
|
1068
1078
|
above would rubber-band behind the pointer, so resizing suspends it. */
|
|
1079
|
+
/* The panel while the widget's code is still arriving (it loads on first
|
|
1080
|
+
open; src/behaviors/deferComponent.ts): the frame above is already
|
|
1081
|
+
drawn, and a spinner holds its centre. */
|
|
1082
|
+
.ds-chat-launcher__loading {
|
|
1083
|
+
flex: 1;
|
|
1084
|
+
display: grid;
|
|
1085
|
+
place-items: center;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1069
1088
|
html[data-chat-resizing] .ds-chat-launcher__panel {
|
|
1070
1089
|
transition: none;
|
|
1071
1090
|
}
|
package/chat/ChatWidget.d.ts
CHANGED
|
@@ -194,7 +194,8 @@ export interface ChatWidgetProps {
|
|
|
194
194
|
/** How the widget slot takes its room. `fit` keeps the welcome screen to
|
|
195
195
|
one viewport: the composer holds dead centre as it does over the
|
|
196
196
|
starters, the widgets hanging below it, and rides up only when they
|
|
197
|
-
need more than half the room
|
|
197
|
+
need more than half the room; widgets taller than the whole widget
|
|
198
|
+
scroll with the welcome rather than being cut off. `scroll` turns the welcome screen into a page: the
|
|
198
199
|
greeting and composer take the opening of the viewport, the widgets
|
|
199
200
|
run on below the fold, and the whole welcome scrolls as one. */
|
|
200
201
|
widgetsLayout?: 'fit' | 'scroll';
|