rift-ds 1.30.0 → 1.31.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/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/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 +4 -1
- package/chat/ChatLauncher.js +6 -1
- package/chat/ChatProvider.d.ts +19 -2
- package/chat/ChatProvider.js +26 -3
- package/chat/ChatWidget.css +10 -0
- package/chat/ChatWidget.d.ts +2 -1
- package/chat/ChatWidget.js +8 -6
- 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/index.d.ts +2 -2
- package/chat/index.js +5 -1
- package/chat/registry.json.d.ts +2 -2
- 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/AppSidebar/AppSidebar.css +12 -0
- package/components/ButtonGroup/ButtonGroup.css +10 -1
- package/components/Chart/RadarChart.js +24 -10
- package/components/DataTable/DataTable.css +17 -2
- package/components/DataTable/DataTable.d.ts +14 -2
- package/components/DataTable/DataTable.js +13 -2
- package/components/DataTable/periodColumns.d.ts +37 -0
- package/components/DataTable/periodColumns.js +48 -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/EventCalendar/EventCalendar.css +54 -0
- package/components/EventCalendar/EventCalendar.d.ts +27 -5
- package/components/EventCalendar/EventCalendar.js +50 -15
- package/components/FunnelChart/FunnelChart.js +33 -22
- package/components/Globe/Globe.css +7 -0
- package/components/Globe/Globe.js +1 -1
- package/components/Table/Table.css +7 -0
- package/components/Table/Table.js +1 -1
- package/components/Tabs/Tabs.css +21 -3
- package/components/Timeline/Timeline.css +8 -0
- package/components/Widget/Widget.css +2 -0
- package/components/WorldMap/WorldMap.css +15 -0
- package/components/WorldMap/WorldMap.js +56 -1
- package/components/registry.json +20 -3
- package/components/registry.json.d.ts +20 -3
- package/components/registry.json.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +6 -0
- package/package.json +1 -1
- 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
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ An open source React design system built for AI products and coding agents: comp
|
|
|
13
13
|
|
|
14
14
|
## Why Rift DS
|
|
15
15
|
|
|
16
|
-
- **<!-- component-count -->
|
|
16
|
+
- **<!-- component-count -->189<!-- /component-count --> components.** Buttons, forms and tables through to charts, navigation and overlays, each typed and documented with live examples. Every one forwards a ref and your own attributes to its element, state you can own works controlled or uncontrolled (a modal opens when your app says so, by design), and every word a component writes has a prop you can localise. The build checks the first two on every component, and the words wherever they sit in markup. React and React DOM are the only required peer dependencies.
|
|
17
17
|
- **A matching <!-- figma-kit-link -->[Figma kit](https://www.figma.com/community/file/1701820123445795117)<!-- /figma-kit-link -->.** Every component has a page in it, with a sticker sheet of its states, built on variables named after the same tokens. Duplicate it from the Figma Community to design with the same system.
|
|
18
18
|
- **AI patterns, the whole chat and templates, ready to use.** Composer, streaming chat thread, tool calls, reasoning and thread panel are in the box, the complete AI chat ships assembled as one widget that one command scaffolds, and the docs site has complete template screens built from them.
|
|
19
19
|
- **Fully themeable.** The shipped themes are complete looks to start from, each in light and dark. One `data-brand` attribute applies a theme, and a few CSS overrides make your own.
|
|
@@ -54,6 +54,8 @@ The whole AI chat ships as one widget: the panel with its docked, overlay and ta
|
|
|
54
54
|
npx rift-ds init chat
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
Add `--actions` for a chat that proposes changes to the page's records and applies one only when the reader confirms it on the card.
|
|
58
|
+
|
|
57
59
|
The panel alone, with no route behind it, is three imports:
|
|
58
60
|
|
|
59
61
|
```tsx
|
|
@@ -101,7 +103,7 @@ import 'rift-ds/tokens/presets/presets.css';
|
|
|
101
103
|
```
|
|
102
104
|
|
|
103
105
|
- **Dark mode**: `data-theme="dark"` on the root element; light is the default.
|
|
104
|
-
- **Theme names**: a preset's id is its `data-brand` value and stylesheet name,
|
|
106
|
+
- **Theme names**: a preset's id is its `data-brand` value and stylesheet name, and a theme shown under another name answers to that name in lowercase too (Signal, id `plum`, also applies as `data-brand="signal"` and `tokens/presets/signal.css`). `SHIPPED_THEMES` from `rift-ds/tokens/values` lists every theme with its name and attribute, and `shippedThemeOptions()` hands ThemePicker the same list with each theme's swatch. To apply a stored theme before first paint, pass `colorModeScript({ brandStorageKey })` the key you keep it under.
|
|
105
107
|
- **Page colours**: the token stylesheet defines custom properties and styles no element, so paint the page once: set `background: var(--color-bg-page-primary)`, `color: var(--color-text-primary)` and `font-family: var(--font-family-primary)` on `body`. Without it a dark theme lands as dark components on a white page.
|
|
106
108
|
- **Your own brand**: every semantic token chains to a primitive, so overriding one primitive re-themes everything built on it. The [playground](https://rift-ds.com/playground) restyles the system live and copies out a complete, paste-ready override.
|
|
107
109
|
- **One part of a shipped theme**: the token and theme stylesheets sit in cascade layers (`rift.tokens`, then `rift.preset`), so any rule of your own outranks them whatever its selector. A plain `:root { --font-family-primary: … }` keeps a preset's colours with your face, in light and dark alike. To set a default that a preset still replaces, declare it inside `@layer rift.tokens { … }`.
|
|
@@ -110,13 +112,13 @@ import 'rift-ds/tokens/presets/presets.css';
|
|
|
110
112
|
|
|
111
113
|
## Components
|
|
112
114
|
|
|
113
|
-
<!-- component-count -->
|
|
115
|
+
<!-- component-count -->189<!-- /component-count --> components, including a chat set for AI products (Chat thread, Composer, Tool call, Reasoning, Thread panel) and Shader field, a WebGL2 ambient background whose light sources read your colour tokens at runtime, so it re-themes with everything else. Details and live examples are on the [docs site](https://rift-ds.com/components).
|
|
114
116
|
|
|
115
117
|
<details>
|
|
116
118
|
<summary>The full list</summary>
|
|
117
119
|
|
|
118
120
|
<!-- component-list:start -->
|
|
119
|
-
Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Checklist · Chip · Circular button · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Currency input · Data table · Date input · Date picker · Date range picker · Deadline · Description list · Dialog · Divider · Document chip · Document viewer · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Error summary · Event calendar · Field · Figure · File input · File row · Filter bar · Form section · Funnel chart · Gantt chart · Gauge · Globe · Grid · Heading · Hover card · Icon · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link · Link list · List · Map callout · Map legend · Masked input · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Org chart · Page header · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Resource timeline · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Shader scene · Sidebar panel · Signature pad · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stack · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Text · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · Wizard · World map
|
|
121
|
+
Accordion · Action card · Action readout · Agent plan · Agent rail · Agent status · AI button · Alert · Alert dialog · Anchor nav · Animated number · App layout · App sidebar · Area chart · Artifact card · Artifact panel · Attachment drop zone · Attachment group · Attachment tile · Attachment viewer · Avatar · Avatar group · Badge · Banner · Bar chart · Bento tile · Bento tile art · Bottom nav · Breadcrumb · Button · Button group · Card · Card stack · Carousel · Chat header · Chat marker · Chat message · Chat thread · Checkbox · Checklist · Chip · Circular button · Code block · Code diff · Colour picker · Combo chart · Combobox · Command palette · Command palette trigger · Composer · Contact card · Context menu · Contribution graph · Currency input · Data table · Date input · Date picker · Date range picker · Deadline · Decision row · Description list · Dialog · Divider · Document chip · Document viewer · Drawer · Dropdown · Dropdown menu · Empty state · Entity card · Entity switcher · Error summary · Event calendar · Field · Figure · File input · File row · Filter bar · Form section · Funnel chart · Gantt chart · Gauge · Globe · Grid · Heading · Hover card · Icon · Image compare · Input · Inspector colour picker · Inspector dropdown · Inspector input · Inspector section · Inspector segments · Inspector slider · Inspector toggle switch · Instructions · Interrupt card · Kbd · Legend tile · Lightbox · Line chart · Link · Link list · List · Map callout · Map legend · Masked input · Mega menu · Mention · Message actions · Message card · Meter · Model picker · Nav · Nav list · Notification centre · Number input · Org chart · Page header · Pagination · Panel · Pie chart · Pin input · Pixel avatar · Popover · Progress bar · Progressive blur · Prompt suggestions · Prose · Question card · Quote · Radar chart · Radial chart · Radio button · Rating · Reasoning · Resource timeline · Rich dropdown · Scatter chart · Section title · Segmented control · Selection card · Shader field · Shader scene · Sidebar panel · Signature pad · Site header · Skeleton · Slider · Source chip · Source trail · Sparkline · Spinner · Split button · Split pane · Stack · Stacked bar chart · Stat · Status dot · Stepper · Streaming text · Swatch · Table · Table toolbar · Tabs · Tag input · Text · Textarea · Theme picker · Theme toggle · Thread panel · Thread tabs · Time picker · Timeline · Toast · Toggle group · Toggle switch · Tool call · Toolbar · Tooltip · Top app bar · Tree view · Treemap · Usage card · Waveform · Widget · Wizard · World map
|
|
120
122
|
<!-- component-list:end -->
|
|
121
123
|
|
|
122
124
|
</details>
|
package/behaviors/locale.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export declare function rotateWeek<T>(sundayFirst: readonly T[], start: Weekday)
|
|
|
28
28
|
export declare const weekdayOffset: (day: number, start: Weekday) => number;
|
|
29
29
|
/** The seven weekday names in `locale`, Sunday first, at the given width. */
|
|
30
30
|
export declare function weekdayNamesIn(locale: string, width: 'long' | 'short' | 'narrow'): string[];
|
|
31
|
+
/**
|
|
32
|
+
* The weekday names a seven-column calendar heads its columns with: the
|
|
33
|
+
* locale's short names where they are abbreviations (`Mo.`, `lun.`, `пн`),
|
|
34
|
+
* and its narrow ones where its short names are whole words (Arabic's
|
|
35
|
+
* `الأربعاء`), which would widen a column past the day under it on a phone.
|
|
36
|
+
*/
|
|
37
|
+
export declare function weekdayHeadersIn(locale: string): string[];
|
|
31
38
|
/** Whether `locale` is written in English, the language every built-in label defaults to. */
|
|
32
39
|
export declare function isEnglish(locale: string): boolean;
|
|
33
40
|
/** Whether `locale` writes times on a 12-hour clock (en-US) rather than a 24-hour one (en-GB, de-DE). */
|
package/behaviors/locale.js
CHANGED
|
@@ -31,6 +31,10 @@ function weekdayNamesIn(locale, width) {
|
|
|
31
31
|
const format = new Intl.DateTimeFormat(locale, { weekday: width, timeZone: "UTC" });
|
|
32
32
|
return Array.from({ length: 7 }, (_, day) => format.format(Date.UTC(2023, 0, 1 + day)));
|
|
33
33
|
}
|
|
34
|
+
function weekdayHeadersIn(locale) {
|
|
35
|
+
const short = weekdayNamesIn(locale, "short");
|
|
36
|
+
return short.some((name) => Array.from(name).length > 4) ? weekdayNamesIn(locale, "narrow") : short;
|
|
37
|
+
}
|
|
34
38
|
function isEnglish(locale) {
|
|
35
39
|
try {
|
|
36
40
|
return new Intl.Locale(locale).language === "en";
|
|
@@ -82,6 +86,7 @@ export {
|
|
|
82
86
|
rotateWeek,
|
|
83
87
|
uses12HourClock,
|
|
84
88
|
weekStartOf,
|
|
89
|
+
weekdayHeadersIn,
|
|
85
90
|
weekdayNamesIn,
|
|
86
91
|
weekdayOffset
|
|
87
92
|
};
|
package/behaviors/shell.css
CHANGED
|
@@ -117,3 +117,36 @@
|
|
|
117
117
|
background-color: var(--ds-shell-backdrop-fill);
|
|
118
118
|
backdrop-filter: var(--ds-shell-backdrop-filter);
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
/* Room for a docked chat. ChatLauncher marks <html> with data-chat="docked"
|
|
122
|
+
(or "docked-left") while its panel is docked, and keeps the panel's width
|
|
123
|
+
in --ds-chat-width and its gap off the window edge in --ds-chat-inset
|
|
124
|
+
(src/chat/ChatWidget.css). The outermost app shell gives up that width
|
|
125
|
+
plus that gap on the docked side, so in every mode the content ends one
|
|
126
|
+
gap short of the panel, as the panel ends one gap short of the window,
|
|
127
|
+
and no host writes its own rule. The plane still runs under the panel,
|
|
128
|
+
so the gap shows the plane. A chat seated as the page (its rails carry
|
|
129
|
+
the marker too) never pads for itself. A host that already makes room
|
|
130
|
+
on its own (a site that pads its body) sets --ds-shell-chat-room to 0px
|
|
131
|
+
on <html> to opt out. The dock is a screen edge the reader picks, not a
|
|
132
|
+
reading direction. */
|
|
133
|
+
:root {
|
|
134
|
+
--ds-shell-chat-room: calc(var(--ds-chat-width, 420px) + var(--ds-chat-inset, 20px));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
html[data-chat='docked'] :where([data-ds-shell]:not(.ds-chat-widget__rails)):not(:where([data-ds-shell] *)) {
|
|
138
|
+
padding-right: var(--ds-shell-chat-room); /* ds-allow(physical): the panel docks to the screen edge the reader picked */
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
html[data-chat='docked-left'] :where([data-ds-shell]:not(.ds-chat-widget__rails)):not(:where([data-ds-shell] *)) {
|
|
142
|
+
padding-left: var(--ds-shell-chat-room); /* ds-allow(physical): the panel docks to the screen edge the reader picked */
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
:where([data-ds-shell]) {
|
|
146
|
+
transition: padding var(--motion-duration-slow) var(--motion-ease-emphasized);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* The widen grip drives the width frame by frame, so the room follows it at once. */
|
|
150
|
+
html[data-chat-resizing] :where([data-ds-shell]) {
|
|
151
|
+
transition: none;
|
|
152
|
+
}
|
package/bin/rift-ds.mjs
CHANGED
|
@@ -67,6 +67,17 @@ const MANIFEST_URL = `${SITE_ORIGIN}/skill/manifest.json`;
|
|
|
67
67
|
const DEFAULT_DIR = join('.claude', 'skills');
|
|
68
68
|
const TEMPLATES_ROOT = join(dirname(fileURLToPath(import.meta.url)), 'templates');
|
|
69
69
|
const TEMPLATES_DIR = join(TEMPLATES_ROOT, 'chat');
|
|
70
|
+
/*
|
|
71
|
+
* The chat templates' propose-and-confirm files, written only by
|
|
72
|
+
* `init chat --actions`: a `<name>.actions.<ext>` file takes the place of
|
|
73
|
+
* `<name>.<ext>`, and the proposals/ folder is added. They live beside the
|
|
74
|
+
* plain chat's so their imports resolve and the library build type-checks
|
|
75
|
+
* them; scripts/validate-chat-widget.mjs holds them to the docs page's
|
|
76
|
+
* ACTIONS_SCAFFOLD_FILES.
|
|
77
|
+
*/
|
|
78
|
+
const ACTIONS_VARIANT = /\.actions(?=\.[a-z]+$)/;
|
|
79
|
+
const ACTIONS_FOLDER = 'components/chat/proposals/';
|
|
80
|
+
const isActionsOnly = (file) => ACTIONS_VARIANT.test(file) || file.startsWith(ACTIONS_FOLDER);
|
|
70
81
|
const APP_TEMPLATES_DIR = join(TEMPLATES_ROOT, 'app');
|
|
71
82
|
const BLOCKS_DIR = join(TEMPLATES_ROOT, 'blocks');
|
|
72
83
|
|
|
@@ -84,7 +95,7 @@ const CHAT_PEERS = [
|
|
|
84
95
|
|
|
85
96
|
const USAGE = `Usage: npx ${PACKAGE_NAME} init [--skill <name>] [--dir <dir>]
|
|
86
97
|
npx ${PACKAGE_NAME} init app [--app <dir>] [--dry-run]
|
|
87
|
-
npx ${PACKAGE_NAME} init chat [--app <dir>] [--dry-run]
|
|
98
|
+
npx ${PACKAGE_NAME} init chat [--actions] [--app <dir>] [--dry-run]
|
|
88
99
|
npx ${PACKAGE_NAME} init block [<name>] [--app <dir>] [--dry-run]
|
|
89
100
|
|
|
90
101
|
init
|
|
@@ -116,6 +127,10 @@ init chat
|
|
|
116
127
|
them, the mount and its model list under components/chat/, and an
|
|
117
128
|
.env.chat.example. Existing files are never overwritten.
|
|
118
129
|
|
|
130
|
+
--actions Write the propose-and-confirm example instead of a plain
|
|
131
|
+
chat: changes defined once for the page and the route, a
|
|
132
|
+
tool that proposes them on a card, the card that confirms,
|
|
133
|
+
and the record the reply opens with
|
|
119
134
|
--app <dir> The app router folder (default: app/ or src/app/, whichever exists)
|
|
120
135
|
--dry-run Print what would be written and write nothing
|
|
121
136
|
|
|
@@ -233,11 +248,11 @@ function findAppDir(app) {
|
|
|
233
248
|
* Writes every template under `base` (or only `files`, paths relative to
|
|
234
249
|
* it) that does not exist yet; returns what was written and skipped.
|
|
235
250
|
*/
|
|
236
|
-
function scaffold(base, appDir, dryRun, files = templateFiles(base)) {
|
|
251
|
+
function scaffold(base, appDir, dryRun, files = templateFiles(base), targetOf = (file) => file) {
|
|
237
252
|
const written = [];
|
|
238
253
|
const skipped = [];
|
|
239
254
|
for (const file of files) {
|
|
240
|
-
const dest = destinationFor(file, appDir);
|
|
255
|
+
const dest = destinationFor(targetOf(file), appDir);
|
|
241
256
|
if (existsSync(dest)) {
|
|
242
257
|
skipped.push(dest);
|
|
243
258
|
continue;
|
|
@@ -327,12 +342,17 @@ function ignoresEnvExample() {
|
|
|
327
342
|
return ignored;
|
|
328
343
|
}
|
|
329
344
|
|
|
330
|
-
function initChat({ app, dryRun }) {
|
|
345
|
+
function initChat({ app, dryRun, actions }) {
|
|
331
346
|
if (!existsSync(TEMPLATES_DIR)) {
|
|
332
347
|
fail('this copy carries no chat templates: run the published bin (npx ' + PACKAGE_NAME + ' init chat).');
|
|
333
348
|
}
|
|
334
349
|
const appDir = findAppDir(app);
|
|
335
|
-
const
|
|
350
|
+
const all = templateFiles(TEMPLATES_DIR);
|
|
351
|
+
const plainName = (file) => file.replace(ACTIONS_VARIANT, '');
|
|
352
|
+
/* With --actions, a variant replaces its plain file and the proposals are added; without it, neither is written. */
|
|
353
|
+
const replaced = new Set(actions ? all.filter((file) => ACTIONS_VARIANT.test(file)).map(plainName) : []);
|
|
354
|
+
const files = all.filter((file) => (actions ? !replaced.has(file) : !isActionsOnly(file)));
|
|
355
|
+
const { written, skipped } = scaffold(TEMPLATES_DIR, appDir, dryRun, files, plainName);
|
|
336
356
|
|
|
337
357
|
console.log(
|
|
338
358
|
dryRun
|
|
@@ -340,14 +360,20 @@ function initChat({ app, dryRun }) {
|
|
|
340
360
|
: `\n✓ Chat scaffolded: ${written.length} files written, ${skipped.length} left alone.`
|
|
341
361
|
);
|
|
342
362
|
console.log(`\nNext:`);
|
|
343
|
-
|
|
363
|
+
/* The actions mount plays no demo, so it needs no recharts. */
|
|
364
|
+
const peers = actions ? CHAT_PEERS.filter((peer) => peer !== 'recharts') : CHAT_PEERS;
|
|
365
|
+
console.log(` 1. Install the peers the chat imports:\n npm install ${peers.join(' ')}`);
|
|
344
366
|
console.log(
|
|
345
367
|
` 2. Render <ChatMount /> at the end of your root layout's body, after the page content:\n` +
|
|
346
368
|
` import { ChatMount } from '${relative(appDir, join(dirname(appDir), 'components', 'chat', 'ChatMount')).split('\\').join('/')}';`
|
|
347
369
|
);
|
|
348
370
|
console.log(
|
|
349
|
-
|
|
350
|
-
`
|
|
371
|
+
actions
|
|
372
|
+
? ` 3. Copy .env.chat.example into .env.local and set ANTHROPIC_API_KEY and CHAT_ENABLED=true: the\n` +
|
|
373
|
+
` propose-and-confirm mount talks to the route, with no scripted demo. Then replace the sample\n` +
|
|
374
|
+
` records and applyPlan in components/chat/proposals/ with your own.`
|
|
375
|
+
: ` 3. Copy .env.chat.example into .env.local. With NEXT_PUBLIC_CHAT_DEMO=true the widget plays a scripted\n` +
|
|
376
|
+
` conversation and needs no key; set ANTHROPIC_API_KEY and CHAT_ENABLED=true to go live.`
|
|
351
377
|
);
|
|
352
378
|
if (ignoresEnvExample()) {
|
|
353
379
|
console.log(
|
|
@@ -415,7 +441,7 @@ function option(flag, what) {
|
|
|
415
441
|
if (args[1] === 'chat' || args[1] === 'app' || args[1] === 'block') {
|
|
416
442
|
const appFlag = option('--app', 'a directory');
|
|
417
443
|
const scaffoldArgs = { app: appFlag ? resolve(appFlag) : undefined, dryRun: args.includes('--dry-run') };
|
|
418
|
-
if (args[1] === 'chat') initChat(scaffoldArgs);
|
|
444
|
+
if (args[1] === 'chat') initChat({ ...scaffoldArgs, actions: args.includes('--actions') });
|
|
419
445
|
else if (args[1] === 'app') initApp(scaffoldArgs);
|
|
420
446
|
else initBlock({ ...scaffoldArgs, name: args[2] && !args[2].startsWith('--') ? args[2] : undefined });
|
|
421
447
|
} else {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The plan: rows of work grouped by team, one editable column per week from
|
|
5
|
+
* periodColumns, a row total from totalOf, each team's subtotal on its group
|
|
6
|
+
* row and the sum of every week in the totals row. Edits are kept in this
|
|
7
|
+
* component's state; save them to your own store in onCellEdit.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { useState } from 'react';
|
|
11
|
+
import { DataTable, periodColumns, totalOf, type DataTableColumn, type DataTableRow } from 'rift-ds/components/DataTable/DataTable';
|
|
12
|
+
|
|
13
|
+
/** The first week shown, as YYYY-MM-DD. Yours is probably this week's Monday. */
|
|
14
|
+
const START = '2026-03-02';
|
|
15
|
+
const WEEKS = periodColumns({
|
|
16
|
+
start: START,
|
|
17
|
+
count: 6,
|
|
18
|
+
unit: 'week',
|
|
19
|
+
keyPrefix: 'w:',
|
|
20
|
+
column: { type: 'number', align: 'end', editable: true, aggregate: 'sum', minWidth: 88 },
|
|
21
|
+
});
|
|
22
|
+
const WEEK_KEYS = WEEKS.map((column) => column.key);
|
|
23
|
+
|
|
24
|
+
const COLUMNS: DataTableColumn[] = [
|
|
25
|
+
{ key: 'work', header: 'Work', rowHeader: true, pin: 'start', minWidth: 180 },
|
|
26
|
+
{ key: 'team', header: 'Team', groupable: true },
|
|
27
|
+
...WEEKS,
|
|
28
|
+
{ key: 'total', header: 'Total', type: 'number', align: 'end', compute: totalOf(WEEK_KEYS), aggregate: 'sum', pin: 'end' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const PLAN: [string, string, number[]][] = [
|
|
32
|
+
['Checkout redesign', 'Design', [4, 5, 5, 3, 2, 0]],
|
|
33
|
+
['Help centre refresh', 'Design', [1, 1, 2, 3, 3, 2]],
|
|
34
|
+
['Payments migration', 'Engineering', [8, 8, 10, 10, 6, 4]],
|
|
35
|
+
['Search indexing', 'Engineering', [3, 3, 2, 2, 4, 5]],
|
|
36
|
+
['Spring launch', 'Marketing', [2, 2, 3, 5, 6, 6]],
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const ROWS: DataTableRow[] = PLAN.map(([work, team, days], index) => ({
|
|
40
|
+
id: `p${index + 1}`,
|
|
41
|
+
values: { work, team, ...Object.fromEntries(WEEK_KEYS.map((key, i) => [key, days[i]])) },
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
export function PlannerGrid() {
|
|
45
|
+
const [rows, setRows] = useState(ROWS);
|
|
46
|
+
return (
|
|
47
|
+
<DataTable
|
|
48
|
+
caption="Days planned by week"
|
|
49
|
+
columns={COLUMNS}
|
|
50
|
+
rows={rows}
|
|
51
|
+
defaultGrouping={['team']}
|
|
52
|
+
totalsRow
|
|
53
|
+
onCellEdit={({ row, key, value }) =>
|
|
54
|
+
setRows((current) => current.map((r) => (r.id === row.id ? { ...r, values: { ...r.values, [key]: value } } : r)))
|
|
55
|
+
}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Requests waiting on a decision, each a DecisionRow that settles to the
|
|
5
|
+
* answer and offers Undo. The statuses live here; send each decision to your
|
|
6
|
+
* own store in onStatusChange.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
import { Avatar } from 'rift-ds/components/Avatar/Avatar';
|
|
11
|
+
import { DecisionRow, type DecisionRowStatus } from 'rift-ds/components/DecisionRow/DecisionRow';
|
|
12
|
+
import { Widget } from 'rift-ds/components/Widget/Widget';
|
|
13
|
+
|
|
14
|
+
const REQUESTS = [
|
|
15
|
+
{ id: 'r1', name: 'Priya Natarajan', what: 'Two more days on search', when: '10m ago' },
|
|
16
|
+
{ id: 'r2', name: 'Tom Okafor', what: 'Move the launch a week', when: 'Yesterday' },
|
|
17
|
+
{ id: 'r3', name: 'Lena Fischer', what: 'A designer for help centre', when: 'Mon' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export function Requests({ className }: { className?: string }) {
|
|
21
|
+
const [statuses, setStatuses] = useState<Record<string, DecisionRowStatus>>({});
|
|
22
|
+
return (
|
|
23
|
+
<Widget className={className} title="Waiting on you" count={REQUESTS.filter((r) => (statuses[r.id] ?? 'pending') === 'pending').length}>
|
|
24
|
+
{REQUESTS.map((request) => (
|
|
25
|
+
<DecisionRow
|
|
26
|
+
key={request.id}
|
|
27
|
+
title={request.name}
|
|
28
|
+
description={request.what}
|
|
29
|
+
meta={request.when}
|
|
30
|
+
leading={<Avatar name={request.name} size="sm" />}
|
|
31
|
+
status={statuses[request.id] ?? 'pending'}
|
|
32
|
+
onStatusChange={(status) => setStatuses((current) => ({ ...current, [request.id]: status }))}
|
|
33
|
+
onUndo={() => {}}
|
|
34
|
+
acceptLabel="Approve"
|
|
35
|
+
declineLabel="Deny"
|
|
36
|
+
acceptedLabel="Approved"
|
|
37
|
+
declinedLabel="Denied"
|
|
38
|
+
/>
|
|
39
|
+
))}
|
|
40
|
+
</Widget>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* The plan takes the column's whole width, so as many weeks show as the
|
|
2
|
+
screen has room for before the table scrolls; the queue sits under it at
|
|
3
|
+
a reading width, where a name, a fact and two buttons fit on one line. */
|
|
4
|
+
|
|
5
|
+
.layout {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: var(--gap-400);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.plan {
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.queue {
|
|
16
|
+
max-width: 560px; /* the queue's reading width */
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The planner block: the app shell with a plan laid out across weeks, one
|
|
3
|
+
* editable column per week, a total for each row, a subtotal for each team
|
|
4
|
+
* and a sum for each week, beside a queue of requests waiting on a yes or a
|
|
5
|
+
* no. The figures are placeholders; read and write your own (PlannerGrid.tsx
|
|
6
|
+
* and Requests.tsx beside this page hold them).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Button } from 'rift-ds/components/Button/Button';
|
|
10
|
+
import { Widget } from 'rift-ds/components/Widget/Widget';
|
|
11
|
+
import { AppShell } from '../../components/blocks/AppShell';
|
|
12
|
+
import { PlannerGrid } from './PlannerGrid';
|
|
13
|
+
import { Requests } from './Requests';
|
|
14
|
+
import styles from './page.module.css';
|
|
15
|
+
|
|
16
|
+
export default function PlannerPage() {
|
|
17
|
+
return (
|
|
18
|
+
<AppShell
|
|
19
|
+
activeKey="projects"
|
|
20
|
+
breadcrumb={[{ label: 'Acme', href: '#' }, { label: 'Planner' }]}
|
|
21
|
+
title="Planner"
|
|
22
|
+
actions={<Button label="Add a row" variant="secondary" iconLeft="add" />}
|
|
23
|
+
>
|
|
24
|
+
<div className={styles.layout}>
|
|
25
|
+
<Widget title="Days planned by week" padding="none" className={styles.plan}>
|
|
26
|
+
<PlannerGrid />
|
|
27
|
+
</Widget>
|
|
28
|
+
<Requests className={styles.queue} />
|
|
29
|
+
</div>
|
|
30
|
+
</AppShell>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -38,6 +38,20 @@
|
|
|
38
38
|
"app/settings/ProfileForm.tsx"
|
|
39
39
|
]
|
|
40
40
|
},
|
|
41
|
+
{
|
|
42
|
+
"name": "planner",
|
|
43
|
+
"label": "Planner",
|
|
44
|
+
"description": "The app shell with a plan across weeks, each cell editable with totals down and across, over a queue of requests to decide.",
|
|
45
|
+
"route": "/planner",
|
|
46
|
+
"files": [
|
|
47
|
+
"components/blocks/AppShell.tsx",
|
|
48
|
+
"components/blocks/AppShell.module.css",
|
|
49
|
+
"app/planner/page.tsx",
|
|
50
|
+
"app/planner/page.module.css",
|
|
51
|
+
"app/planner/PlannerGrid.tsx",
|
|
52
|
+
"app/planner/Requests.tsx"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
41
55
|
{
|
|
42
56
|
"name": "sign-in",
|
|
43
57
|
"label": "Sign in",
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
confirmationLine,
|
|
3
|
+
createChatHandler,
|
|
4
|
+
planAction,
|
|
5
|
+
sanitiseConfirmation,
|
|
6
|
+
sanitisePath,
|
|
7
|
+
type ActionConfirmation,
|
|
8
|
+
type ChatTool,
|
|
9
|
+
} from 'rift-ds/chat/server';
|
|
10
|
+
import { CHAT_MODELS, DEFAULT_CHAT_MODEL } from '../../../components/chat/models';
|
|
11
|
+
import { ACTIONS, SAMPLE_ITEMS, itemNoun, type ActionId } from '../../../components/chat/proposals/actions';
|
|
12
|
+
import { guardrails } from './guardrails';
|
|
13
|
+
|
|
14
|
+
export const maxDuration = 60;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The propose-and-confirm chat. The model can only propose: its tool plans
|
|
18
|
+
* an action over the records the request means and sends the plan as a
|
|
19
|
+
* `proposal` card, which the reader confirms on the page (ProposalCard.tsx).
|
|
20
|
+
* Nothing here writes. A confirmed message arrives with the page's mark in
|
|
21
|
+
* its context; the route rebuilds it as untrusted input, tells the model
|
|
22
|
+
* whether this message was confirmed on its card, and opens the reply with
|
|
23
|
+
* the record of what was done as a `lead` card.
|
|
24
|
+
*/
|
|
25
|
+
const SYSTEM = `You are the assistant on this page. You can propose changes to the items with the propose_change tool, but you never make a change yourself: the reader confirms it on the card. Say a change is made only when you are told this message was confirmed on its card.`;
|
|
26
|
+
|
|
27
|
+
/** The context the page sends: its path, and the confirmation the page marked, if any. */
|
|
28
|
+
type RequestContext = { path: string | null; confirmation: ActionConfirmation | null };
|
|
29
|
+
|
|
30
|
+
const isItem = (id: string) => id in SAMPLE_ITEMS;
|
|
31
|
+
|
|
32
|
+
/* The browser's context is untrusted: keep a slug path and a confirmation
|
|
33
|
+
rebuilt against the real actions and records, and nothing else. */
|
|
34
|
+
function sanitiseContext(raw: unknown): string | null {
|
|
35
|
+
if (typeof raw !== 'string' || raw.length > 4000) return null;
|
|
36
|
+
try {
|
|
37
|
+
const value = JSON.parse(raw) as Record<string, unknown>;
|
|
38
|
+
const context: RequestContext = {
|
|
39
|
+
path: sanitisePath(value.path),
|
|
40
|
+
confirmation: sanitiseConfirmation(value.confirmation, { actions: ACTIONS, isId: isItem, maxCount: 500 }),
|
|
41
|
+
};
|
|
42
|
+
return JSON.stringify(context);
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const readContext = (context: string | null): RequestContext =>
|
|
49
|
+
context ? (JSON.parse(context) as RequestContext) : { path: null, confirmation: null };
|
|
50
|
+
|
|
51
|
+
const proposeChange: ChatTool = {
|
|
52
|
+
definition: {
|
|
53
|
+
name: 'propose_change',
|
|
54
|
+
description: `Propose a change for the reader to confirm. Actions: ${Object.keys(ACTIONS).join(', ')}. Items: ${Object.entries(SAMPLE_ITEMS)
|
|
55
|
+
.map(([id, item]) => `${id} "${item.title}" (${item.state})`)
|
|
56
|
+
.join('; ')}.`,
|
|
57
|
+
input_schema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
action: { type: 'string', enum: Object.keys(ACTIONS) },
|
|
61
|
+
ids: { type: 'array', items: { type: 'string' } },
|
|
62
|
+
},
|
|
63
|
+
required: ['action', 'ids'],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
tracePoint: () => 'Planned a change',
|
|
67
|
+
execute: (input) => {
|
|
68
|
+
const action = ACTIONS[input.action as ActionId];
|
|
69
|
+
const ids = Array.isArray(input.ids) ? input.ids.filter((id): id is string => typeof id === 'string' && isItem(id)) : [];
|
|
70
|
+
if (!action) return JSON.stringify({ error: 'Unknown action.' });
|
|
71
|
+
const plan = planAction(action, ids.map((id) => ({ id, values: SAMPLE_ITEMS[id] })));
|
|
72
|
+
if (plan.ids.length === 0) return JSON.stringify({ error: 'None of those items can take that change.', skipped: plan.skipped });
|
|
73
|
+
return {
|
|
74
|
+
text: `Proposed on a card for the reader to confirm: ${plan.ids.length} ${itemNoun(plan.ids.length)}. Nothing has changed yet.`,
|
|
75
|
+
card: { kind: 'proposal', data: { ...plan, id: crypto.randomUUID() } },
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handler = createChatHandler({
|
|
81
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
82
|
+
enabled: process.env.CHAT_ENABLED === 'true' && Boolean(process.env.ANTHROPIC_API_KEY),
|
|
83
|
+
system: [{ type: 'text', text: SYSTEM, cache_control: { type: 'ephemeral' } }],
|
|
84
|
+
models: CHAT_MODELS,
|
|
85
|
+
defaultModel: DEFAULT_CHAT_MODEL,
|
|
86
|
+
tools: [proposeChange],
|
|
87
|
+
sanitiseContext,
|
|
88
|
+
/* What the model reads about this request, after the cached block. */
|
|
89
|
+
contextBlock: (context) => {
|
|
90
|
+
const { path, confirmation } = readContext(context);
|
|
91
|
+
return [
|
|
92
|
+
path ? `The reader is on the page ${path}.` : null,
|
|
93
|
+
confirmationLine(confirmation, { actions: ACTIONS, noun: itemNoun }),
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.join('\n\n');
|
|
97
|
+
},
|
|
98
|
+
/* A confirmed message's reply opens with the record of what was done. */
|
|
99
|
+
lead: ({ context }) => {
|
|
100
|
+
const { confirmation } = readContext(context);
|
|
101
|
+
return confirmation ? [{ kind: 'record', data: { action: confirmation.action, count: confirmation.count } }] : [];
|
|
102
|
+
},
|
|
103
|
+
guardrails,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export async function POST(request: Request): Promise<Response> {
|
|
107
|
+
return handler(request);
|
|
108
|
+
}
|
|
@@ -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
|
}
|