rift-ds 1.29.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 -3
- package/behaviors/locale.d.ts +7 -0
- package/behaviors/locale.js +5 -0
- package/behaviors/shell.css +33 -0
- package/bin/rift-ds.mjs +36 -10
- package/bin/templates/app/components/rift/ColorModeScript.tsx +7 -3
- 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/app/settings/ProfileForm.tsx +98 -0
- package/bin/templates/blocks/app/settings/page.module.css +11 -0
- package/bin/templates/blocks/app/settings/page.tsx +84 -0
- package/bin/templates/blocks/components/blocks/AppShell.module.css +8 -41
- package/bin/templates/blocks/components/blocks/AppShell.tsx +9 -11
- package/bin/templates/blocks/registry.json +27 -0
- package/bin/templates/chat/app/api/chat/feedback/route.ts +0 -3
- package/bin/templates/chat/app/api/chat/followups/route.ts +0 -3
- package/bin/templates/chat/app/api/chat/route.actions.ts +108 -0
- package/bin/templates/chat/app/api/chat/route.ts +0 -2
- 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 +9 -2
- 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/Alert/Alert.css +12 -0
- package/components/Alert/Alert.d.ts +2 -0
- package/components/Alert/Alert.js +3 -1
- package/components/AppSidebar/AppSidebar.css +12 -0
- package/components/Attachment/Attachment.css +92 -0
- package/components/Attachment/FileRow.d.ts +47 -0
- package/components/Attachment/FileRow.js +38 -0
- package/components/Avatar/Avatar.css +14 -0
- package/components/Avatar/Avatar.d.ts +3 -1
- package/components/Avatar/Avatar.js +3 -2
- package/components/ButtonGroup/ButtonGroup.css +10 -1
- package/components/Chart/AreaChart.d.ts +2 -0
- package/components/Chart/AreaChart.js +2 -1
- package/components/Chart/BarChart.d.ts +2 -0
- package/components/Chart/BarChart.js +2 -1
- package/components/Chart/ComboChart.d.ts +4 -0
- package/components/Chart/ComboChart.js +4 -2
- package/components/Chart/LineChart.d.ts +2 -0
- package/components/Chart/LineChart.js +2 -1
- package/components/Chart/PieChart.d.ts +4 -4
- package/components/Chart/PieChart.js +1 -1
- package/components/Chart/RadarChart.js +24 -10
- package/components/Chart/ScatterChart.d.ts +2 -0
- package/components/Chart/ScatterChart.js +2 -1
- package/components/Checklist/Checklist.css +123 -0
- package/components/Checklist/Checklist.d.ts +66 -0
- package/components/Checklist/Checklist.js +115 -0
- package/components/CircularButton/CircularButton.css +39 -0
- package/components/CircularButton/CircularButton.d.ts +13 -0
- package/components/CircularButton/CircularButton.js +18 -4
- package/components/ColourSwatch/ColourSwatch.css +3 -1
- package/components/ColourSwatch/ColourSwatch.d.ts +5 -3
- package/components/ColourSwatch/ColourSwatch.js +5 -0
- package/components/Combobox/Combobox.d.ts +4 -2
- package/components/Combobox/Combobox.js +7 -3
- package/components/DataTable/DataTable.css +52 -2
- package/components/DataTable/DataTable.d.ts +47 -3
- package/components/DataTable/DataTable.js +71 -7
- package/components/DataTable/columnTypes.d.ts +1 -1
- package/components/DataTable/columnTypes.js +1 -1
- package/components/DataTable/periodColumns.d.ts +37 -0
- package/components/DataTable/periodColumns.js +48 -0
- package/components/DateInput/DateInput.d.ts +4 -2
- package/components/DateInput/DateInput.js +7 -3
- 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/DescriptionList.css +28 -0
- package/components/DescriptionList/DescriptionList.d.ts +3 -1
- package/components/DescriptionList/DescriptionList.js +4 -3
- package/components/DescriptionList/DescriptionListCopy.js +2 -0
- package/components/Dropdown/Dropdown.d.ts +4 -2
- package/components/Dropdown/Dropdown.js +7 -3
- package/components/EmptyState/EmptyState.css +12 -0
- package/components/EmptyState/EmptyState.d.ts +7 -0
- package/components/EmptyState/EmptyState.js +2 -0
- package/components/EventCalendar/EventCalendar.css +113 -0
- package/components/EventCalendar/EventCalendar.d.ts +48 -4
- package/components/EventCalendar/EventCalendar.js +145 -25
- package/components/FormSection/FormSection.css +70 -0
- package/components/FormSection/FormSection.d.ts +35 -0
- package/components/FormSection/FormSection.js +35 -0
- package/components/FunnelChart/FunnelChart.js +33 -22
- package/components/Globe/Globe.css +7 -0
- package/components/Globe/Globe.js +1 -1
- package/components/Grid/Grid.css +52 -0
- package/components/Grid/Grid.d.ts +30 -0
- package/components/Grid/Grid.js +36 -0
- package/components/Icon/Icon.css +55 -0
- package/components/Icon/Icon.d.ts +27 -0
- package/components/Icon/Icon.js +42 -0
- package/components/NumberInput/NumberInput.d.ts +4 -2
- package/components/NumberInput/NumberInput.js +7 -3
- package/components/OrgChart/OrgChart.css +143 -0
- package/components/OrgChart/OrgChart.d.ts +44 -0
- package/components/OrgChart/OrgChart.js +26 -0
- package/components/PageHeader/PageHeader.css +74 -0
- package/components/PageHeader/PageHeader.d.ts +39 -0
- package/components/PageHeader/PageHeader.js +33 -0
- package/components/Panel/Panel.css +7 -0
- package/components/Panel/Panel.d.ts +5 -2
- package/components/Panel/Panel.js +2 -1
- package/components/ResourceTimeline/ResourceTimeline.css +194 -0
- package/components/ResourceTimeline/ResourceTimeline.d.ts +57 -0
- package/components/ResourceTimeline/ResourceTimeline.js +129 -0
- package/components/ShaderField/useShaderField.js +13 -1
- package/components/ShaderScene/ShaderScene.d.ts +3 -2
- package/components/ShaderScene/ShaderScene.js +47 -4
- package/components/Stack/Stack.css +68 -0
- package/components/Stack/Stack.d.ts +37 -0
- package/components/Stack/Stack.js +39 -0
- package/components/Stat/Stat.css +65 -0
- package/components/Stat/Stat.d.ts +7 -1
- package/components/Stat/Stat.js +16 -1
- package/components/Table/Table.css +18 -0
- package/components/Table/Table.d.ts +2 -0
- package/components/Table/Table.js +6 -2
- package/components/Tabs/Tabs.css +44 -3
- package/components/Tabs/Tabs.d.ts +9 -8
- package/components/Tabs/Tabs.js +38 -5
- package/components/Textarea/Textarea.d.ts +4 -2
- package/components/Textarea/Textarea.js +7 -3
- package/components/ThemeToggle/colorMode.d.ts +17 -1
- package/components/ThemeToggle/colorMode.js +11 -2
- package/components/Timeline/Timeline.css +8 -0
- package/components/Widget/Widget.css +23 -0
- package/components/Widget/Widget.d.ts +4 -0
- package/components/Widget/Widget.js +13 -5
- package/components/Wizard/Wizard.css +67 -0
- package/components/Wizard/Wizard.d.ts +54 -0
- package/components/Wizard/Wizard.js +71 -0
- package/components/WorldMap/WorldMap.css +15 -0
- package/components/WorldMap/WorldMap.js +56 -1
- package/components/registry.d.ts +25 -0
- package/components/registry.js +8 -0
- package/components/registry.json +251 -33
- package/components/registry.json.d.ts +251 -33
- package/components/registry.json.js +1 -1
- package/index.d.ts +11 -0
- package/index.js +26 -0
- package/package.json +1 -1
- package/tokens/motion.d.ts +2 -0
- package/tokens/motion.js +2 -0
- 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/tokens/values.d.ts +31 -0
- package/tokens/values.js +16 -0
- package/tokens/values.json.js +1 -1
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
|
@@ -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
|
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';
|
package/chat/ChatWidget.js
CHANGED
|
@@ -27,7 +27,7 @@ import { useChatWidget, ArtifactSeatContext } from "./context.js";
|
|
|
27
27
|
import { DEFAULT_GREETING_COPY, subscribeClock, greetingFor, serverGreeting } from "./greeting.js";
|
|
28
28
|
import { CHAT_PLACEMENTS, chatPlacement } from "./placement.js";
|
|
29
29
|
import { ASIDE_WITH_THREADS_MIN_WIDTH, THREADS_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH } from "./queries.js";
|
|
30
|
-
import {
|
|
30
|
+
import { keepFittingSuggestions } from "./suggestions.js";
|
|
31
31
|
import { TurnCard } from "./TurnContent.js";
|
|
32
32
|
import { isBlockingQuestion } from "./questions.js";
|
|
33
33
|
import { ReplyBody } from "./TurnQuestion.js";
|
|
@@ -199,7 +199,7 @@ function ChatWidget({
|
|
|
199
199
|
() => greetingFor((/* @__PURE__ */ new Date()).getHours(), greetingCopy),
|
|
200
200
|
serverGreeting
|
|
201
201
|
);
|
|
202
|
-
const starters = (startersInput ?? []
|
|
202
|
+
const starters = keepFittingSuggestions(startersInput ?? [], (starter) => starter.label, "ChatWidget starters");
|
|
203
203
|
const composerRef = useRef(null);
|
|
204
204
|
const focusComposer = () => composerRef.current?.focus({ preventScroll: true });
|
|
205
205
|
useEffect(() => {
|
|
@@ -279,6 +279,7 @@ function ChatWidget({
|
|
|
279
279
|
const [artifactEmptyOpen, setArtifactEmptyOpen] = useState(false);
|
|
280
280
|
const [artifactExpandedWanted, setArtifactExpanded] = useState(false);
|
|
281
281
|
const wasAsideWideRef = useRef(true);
|
|
282
|
+
const [seatMeasured, setSeatMeasured] = useState(false);
|
|
282
283
|
useEffect(() => {
|
|
283
284
|
if (!hasRails) return;
|
|
284
285
|
const host = railsHostRef.current;
|
|
@@ -298,6 +299,7 @@ function ChatWidget({
|
|
|
298
299
|
closeArtifact();
|
|
299
300
|
}
|
|
300
301
|
wasAsideWideRef.current = asideRoom;
|
|
302
|
+
setSeatMeasured(true);
|
|
301
303
|
};
|
|
302
304
|
measure();
|
|
303
305
|
const observer = new ResizeObserver(measure);
|
|
@@ -806,7 +808,7 @@ function ChatWidget({
|
|
|
806
808
|
artifacts && !asideWide && /* @__PURE__ */ jsxs(
|
|
807
809
|
"div",
|
|
808
810
|
{
|
|
809
|
-
className: `ds-chat-widget__aside-overlay ${artifactShown ? "ds-chat-widget__aside-overlay--open" : ""}`,
|
|
811
|
+
className: `ds-chat-widget__aside-overlay ${artifactShown && seatMeasured ? "ds-chat-widget__aside-overlay--open" : ""}`,
|
|
810
812
|
children: [
|
|
811
813
|
/* @__PURE__ */ jsx(
|
|
812
814
|
"button",
|
|
@@ -814,7 +816,7 @@ function ChatWidget({
|
|
|
814
816
|
type: "button",
|
|
815
817
|
className: "ds-chat-widget__rail-scrim",
|
|
816
818
|
"aria-label": closeArtifactLabel,
|
|
817
|
-
tabIndex: artifactShown ? 0 : -1,
|
|
819
|
+
tabIndex: artifactShown && seatMeasured ? 0 : -1,
|
|
818
820
|
onClick: closeArtifactPanel
|
|
819
821
|
}
|
|
820
822
|
),
|
|
@@ -864,7 +866,7 @@ function ChatWidget({
|
|
|
864
866
|
renderAside && !asideWide && /* @__PURE__ */ jsxs(
|
|
865
867
|
"div",
|
|
866
868
|
{
|
|
867
|
-
className: `ds-chat-widget__aside-overlay ${asideShown ? "ds-chat-widget__aside-overlay--open" : ""}`,
|
|
869
|
+
className: `ds-chat-widget__aside-overlay ${asideShown && seatMeasured ? "ds-chat-widget__aside-overlay--open" : ""}`,
|
|
868
870
|
children: [
|
|
869
871
|
/* @__PURE__ */ jsx(
|
|
870
872
|
"button",
|
|
@@ -872,7 +874,7 @@ function ChatWidget({
|
|
|
872
874
|
type: "button",
|
|
873
875
|
className: "ds-chat-widget__rail-scrim",
|
|
874
876
|
"aria-label": closeAgentLabel,
|
|
875
|
-
tabIndex: asideShown ? 0 : -1,
|
|
877
|
+
tabIndex: asideShown && seatMeasured ? 0 : -1,
|
|
876
878
|
onClick: closeAside
|
|
877
879
|
}
|
|
878
880
|
),
|
package/chat/actions.d.ts
CHANGED
|
@@ -25,7 +25,16 @@
|
|
|
25
25
|
* the route rebuilds the mark from the request (`sanitiseConfirmation`), and
|
|
26
26
|
* the model is told whether this message was confirmed on its card
|
|
27
27
|
* (`confirmationLine`). A typed "yes, cancel them" carries no mark.
|
|
28
|
+
*
|
|
29
|
+
* A change can also be a sequence: several different actions in order, where
|
|
30
|
+
* each one acts on the records as the ones before it left them ("close the
|
|
31
|
+
* open items, then archive the closed ones"). `planSequence` dry-runs the
|
|
32
|
+
* steps in turn over one set of records, and the reader confirms the whole
|
|
33
|
+
* sequence once; its confirmation carries each step (`confirmSequence`), and
|
|
34
|
+
* `confirmationLine` tells the model all of them, in order. A single action
|
|
35
|
+
* is a sequence of one.
|
|
28
36
|
*/
|
|
37
|
+
export { defineContext, type ContextField, type ContextShape, type ContextValues, type ContextSchema } from './contextSchema';
|
|
29
38
|
export interface ChatAction<Values, Edit = Partial<Values>> {
|
|
30
39
|
/** A stable id the server and the page share. */
|
|
31
40
|
id: string;
|
|
@@ -61,12 +70,42 @@ export declare function planAction<Values>(action: ChatAction<Values, unknown>,
|
|
|
61
70
|
id: string;
|
|
62
71
|
values: Values;
|
|
63
72
|
}[]): ActionPlan;
|
|
64
|
-
/**
|
|
65
|
-
export interface
|
|
73
|
+
/** One step of a sequence: an action, and the records it is meant for. */
|
|
74
|
+
export interface SequenceStep<Values> {
|
|
75
|
+
action: ChatAction<Values, unknown>;
|
|
76
|
+
/** The records this step means, by id. A record the sequence was not handed is ignored. */
|
|
77
|
+
ids: readonly string[];
|
|
78
|
+
}
|
|
79
|
+
/** What a sequence would do: each step's plan, in order, worked out over the records as the steps before it left them. */
|
|
80
|
+
export interface SequencePlan {
|
|
81
|
+
steps: ActionPlan[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The dry run of a sequence. Each step is planned over the records as the
|
|
85
|
+
* earlier steps would leave them, so a step that depends on the one before
|
|
86
|
+
* it (archive what the first step closed) counts the right records. Changes
|
|
87
|
+
* nothing: the writes are simulated on copies.
|
|
88
|
+
*/
|
|
89
|
+
export declare function planSequence<Values extends object>(steps: readonly SequenceStep<Values>[], records: {
|
|
90
|
+
id: string;
|
|
91
|
+
values: Values;
|
|
92
|
+
}[]): SequencePlan;
|
|
93
|
+
/** One confirmed step: which action, how many records it changed, and their ids. */
|
|
94
|
+
export interface ConfirmedStep<Id extends string = string> {
|
|
66
95
|
action: Id;
|
|
67
96
|
count: number;
|
|
68
97
|
ids: string[];
|
|
69
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* A change the reader confirmed on its card: which action, how many records it
|
|
101
|
+
* changed, and their ids. A confirmed sequence carries every step in `steps`,
|
|
102
|
+
* in order, with the first step's action and the total count at the top.
|
|
103
|
+
*/
|
|
104
|
+
export interface ActionConfirmation<Id extends string = string> extends ConfirmedStep<Id> {
|
|
105
|
+
steps?: ConfirmedStep<Id>[];
|
|
106
|
+
}
|
|
107
|
+
/** The confirmation for a sequence plan, ready to mark: its steps, the first step's action, the total count. Steps that change nothing are left out; null when none change anything. */
|
|
108
|
+
export declare function confirmSequence<Id extends string = string>(plan: SequencePlan, maxIds?: number): ActionConfirmation<Id> | null;
|
|
70
109
|
/** The page's one-shot mark: set on Confirm, read once by the next request, then gone. */
|
|
71
110
|
export interface ConfirmationMark<Id extends string = string> {
|
|
72
111
|
/** Marks the request about to carry the reader's confirmation. */
|
|
@@ -85,14 +124,21 @@ export interface SanitiseConfirmationOptions {
|
|
|
85
124
|
maxCount: number;
|
|
86
125
|
/** The most ids kept. Defaults to 50. */
|
|
87
126
|
maxIds?: number;
|
|
127
|
+
/** The most steps a confirmed sequence may carry. Defaults to 10. */
|
|
128
|
+
maxSteps?: number;
|
|
88
129
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
130
|
+
/**
|
|
131
|
+
* The confirmation a request claims, rebuilt as untrusted input: a known
|
|
132
|
+
* action, a count in range, real ids only. A sequence's steps are each held
|
|
133
|
+
* to the same rules, and one bad step drops the whole claim, so the model is
|
|
134
|
+
* never told part of a sequence was confirmed. Null for none.
|
|
135
|
+
*/
|
|
136
|
+
export declare function sanitiseConfirmation(value: unknown, { actions, isId, maxCount, maxIds, maxSteps }: SanitiseConfirmationOptions): ActionConfirmation | null;
|
|
91
137
|
export interface ConfirmationLineOptions {
|
|
92
138
|
/** The actions a confirmation may name, by id, for the words that say what was done. */
|
|
93
139
|
actions: Record<string, Pick<ChatAction<never, unknown>, 'done'>>;
|
|
94
|
-
/** The records' noun for a count: "order" for one, "orders" for more. */
|
|
95
|
-
noun: (count: number) => string;
|
|
140
|
+
/** The records' noun for a count: "order" for one, "orders" for more. Handed the step's action id too, for a sequence whose steps act on different records. */
|
|
141
|
+
noun: (count: number, action: string) => string;
|
|
96
142
|
/** The locale the count is written in. */
|
|
97
143
|
locale?: string;
|
|
98
144
|
}
|
package/chat/actions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_LOCALE } from "../behaviors/locale.js";
|
|
2
|
+
import { defineContext } from "./contextSchema.js";
|
|
2
3
|
const defineAction = (action) => action;
|
|
3
4
|
function planAction(action, records) {
|
|
4
5
|
const ids = [];
|
|
@@ -10,6 +11,33 @@ function planAction(action, records) {
|
|
|
10
11
|
}
|
|
11
12
|
return { action: action.id, ids, skipped };
|
|
12
13
|
}
|
|
14
|
+
function planSequence(steps, records) {
|
|
15
|
+
const current = new Map(records.map((record) => [record.id, record.values]));
|
|
16
|
+
return {
|
|
17
|
+
steps: steps.map(({ action, ids }) => {
|
|
18
|
+
const meant = ids.flatMap((id) => {
|
|
19
|
+
const values = current.get(id);
|
|
20
|
+
return values ? [{ id, values }] : [];
|
|
21
|
+
});
|
|
22
|
+
const plan = planAction(action, meant);
|
|
23
|
+
for (const id of plan.ids) {
|
|
24
|
+
const values = current.get(id);
|
|
25
|
+
current.set(id, { ...values, ...action.apply(values) });
|
|
26
|
+
}
|
|
27
|
+
return plan;
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function confirmSequence(plan, maxIds = 50) {
|
|
32
|
+
const steps = plan.steps.filter((step) => step.ids.length > 0).map((step) => ({ action: step.action, count: step.ids.length, ids: step.ids.slice(0, maxIds) }));
|
|
33
|
+
if (!steps.length) return null;
|
|
34
|
+
return {
|
|
35
|
+
action: steps[0].action,
|
|
36
|
+
count: steps.reduce((total, step) => total + step.count, 0),
|
|
37
|
+
ids: [...new Set(steps.flatMap((step) => step.ids))].slice(0, maxIds),
|
|
38
|
+
steps
|
|
39
|
+
};
|
|
40
|
+
}
|
|
13
41
|
function createConfirmationMark() {
|
|
14
42
|
let pending = null;
|
|
15
43
|
return {
|
|
@@ -23,25 +51,45 @@ function createConfirmationMark() {
|
|
|
23
51
|
}
|
|
24
52
|
};
|
|
25
53
|
}
|
|
26
|
-
function
|
|
54
|
+
function sanitiseStep(value, known, isId, maxCount, maxIds) {
|
|
27
55
|
const { action, count, ids } = value ?? {};
|
|
28
|
-
const known = Array.isArray(actions) ? actions : Object.keys(actions);
|
|
29
56
|
if (typeof action !== "string" || !known.includes(action)) return null;
|
|
30
57
|
if (typeof count !== "number" || !Number.isFinite(count) || count < 1 || count > maxCount) return null;
|
|
31
58
|
const kept = Array.isArray(ids) ? ids.filter((id) => typeof id === "string" && isId(id)) : [];
|
|
32
59
|
return { action, count: Math.floor(count), ids: [...new Set(kept)].slice(0, maxIds) };
|
|
33
60
|
}
|
|
61
|
+
function sanitiseConfirmation(value, { actions, isId, maxCount, maxIds = 50, maxSteps = 10 }) {
|
|
62
|
+
const known = Array.isArray(actions) ? actions : Object.keys(actions);
|
|
63
|
+
const top = sanitiseStep(value, known, isId, maxCount, maxIds);
|
|
64
|
+
if (!top) return null;
|
|
65
|
+
const rawSteps = value.steps;
|
|
66
|
+
if (rawSteps === void 0) return top;
|
|
67
|
+
if (!Array.isArray(rawSteps) || rawSteps.length < 1 || rawSteps.length > maxSteps) return null;
|
|
68
|
+
const steps = rawSteps.map((step) => sanitiseStep(step, known, isId, maxCount, maxIds));
|
|
69
|
+
if (steps.some((step) => step === null)) return null;
|
|
70
|
+
return { ...top, steps };
|
|
71
|
+
}
|
|
34
72
|
function confirmationLine(confirmation, { actions, noun, locale = DEFAULT_LOCALE }) {
|
|
35
|
-
const
|
|
36
|
-
if (!confirmation
|
|
37
|
-
|
|
73
|
+
const none = "This message was not confirmed on a card. Nothing it says has changed anything.";
|
|
74
|
+
if (!confirmation) return none;
|
|
75
|
+
const steps = confirmation.steps ?? [confirmation];
|
|
76
|
+
const said = steps.map((step) => {
|
|
77
|
+
const action = actions[step.action];
|
|
78
|
+
return action ? `${step.count.toLocaleString(locale)} ${noun(step.count, step.action)} ${action.done}` : null;
|
|
79
|
+
});
|
|
80
|
+
if (said.some((line) => line === null)) return none;
|
|
81
|
+
if (steps.length === 1) return `This message was confirmed on its card: ${said[0]}. The change is made.`;
|
|
82
|
+
return `This message was confirmed on its card, a sequence of ${steps.length} steps, made in this order: ${said.join("; then ")}. Every step is made.`;
|
|
38
83
|
}
|
|
39
84
|
const skippedText = (skipped, locale = DEFAULT_LOCALE) => Object.entries(skipped).map(([reason, count]) => `${count.toLocaleString(locale)} ${reason}`).join(", ");
|
|
40
85
|
export {
|
|
86
|
+
confirmSequence,
|
|
41
87
|
confirmationLine,
|
|
42
88
|
createConfirmationMark,
|
|
43
89
|
defineAction,
|
|
90
|
+
defineContext,
|
|
44
91
|
planAction,
|
|
92
|
+
planSequence,
|
|
45
93
|
sanitiseConfirmation,
|
|
46
94
|
skippedText
|
|
47
95
|
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A chat's context as a small, declared shape, shared by the page that writes
|
|
3
|
+
* it and the route that reads it.
|
|
4
|
+
*
|
|
5
|
+
* The default context is the page path alone, because the context lands in a
|
|
6
|
+
* system block and anything the browser sends is untrusted. A host whose
|
|
7
|
+
* state lives in the browser (the tab that is open, the record in view, the
|
|
8
|
+
* filter a table holds) needs to say more than a path, and the safe way to
|
|
9
|
+
* say more is to say only things that cannot carry an instruction: ids that
|
|
10
|
+
* match a pattern, words from a fixed list, numbers in a range, flags.
|
|
11
|
+
*
|
|
12
|
+
* `defineContext` takes that shape once. The page builds its context with
|
|
13
|
+
* `write` (handed to `getContext`), and the route passes `sanitise` as the
|
|
14
|
+
* handler's `sanitiseContext`. Whatever arrives, `sanitise` keeps only the
|
|
15
|
+
* fields the shape names and only the values each one allows, drops the
|
|
16
|
+
* rest without rejecting the request, and returns the kept fields as a JSON
|
|
17
|
+
* string, or null when nothing survives. `read` parses that string back for
|
|
18
|
+
* a tool. No dependencies, so a page and its route can both import it.
|
|
19
|
+
*/
|
|
20
|
+
/** What one field of a context may hold. */
|
|
21
|
+
export type ContextField =
|
|
22
|
+
/** A same-site path: lowercase slug segments only. */
|
|
23
|
+
{
|
|
24
|
+
kind: 'path';
|
|
25
|
+
}
|
|
26
|
+
/** One word from a fixed list. */
|
|
27
|
+
| {
|
|
28
|
+
kind: 'oneOf';
|
|
29
|
+
values: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** One id matching `pattern`. */
|
|
32
|
+
| {
|
|
33
|
+
kind: 'id';
|
|
34
|
+
pattern: RegExp;
|
|
35
|
+
}
|
|
36
|
+
/** Ids matching `pattern`, at most `max` of them (default 50). */
|
|
37
|
+
| {
|
|
38
|
+
kind: 'ids';
|
|
39
|
+
pattern: RegExp;
|
|
40
|
+
max?: number;
|
|
41
|
+
}
|
|
42
|
+
/** A finite number between `min` and `max`. */
|
|
43
|
+
| {
|
|
44
|
+
kind: 'number';
|
|
45
|
+
min?: number;
|
|
46
|
+
max?: number;
|
|
47
|
+
}
|
|
48
|
+
/** True or false. */
|
|
49
|
+
| {
|
|
50
|
+
kind: 'flag';
|
|
51
|
+
};
|
|
52
|
+
export type ContextShape = Record<string, ContextField>;
|
|
53
|
+
type FieldValue<F extends ContextField> = F extends {
|
|
54
|
+
kind: 'ids';
|
|
55
|
+
} ? string[] : F extends {
|
|
56
|
+
kind: 'number';
|
|
57
|
+
} ? number : F extends {
|
|
58
|
+
kind: 'flag';
|
|
59
|
+
} ? boolean : string;
|
|
60
|
+
/** The values a shape allows, every field optional. */
|
|
61
|
+
export type ContextValues<S extends ContextShape> = {
|
|
62
|
+
[K in keyof S]?: FieldValue<S[K]>;
|
|
63
|
+
};
|
|
64
|
+
export interface ContextSchema<S extends ContextShape> {
|
|
65
|
+
/** The shape, as given. */
|
|
66
|
+
shape: S;
|
|
67
|
+
/** The context string for these values, or null when there are none. What a page returns from `getContext`. */
|
|
68
|
+
write: (values: ContextValues<S>) => string | null;
|
|
69
|
+
/** The handler's `sanitiseContext`: only the fields and values the shape allows, as a JSON string, or null. */
|
|
70
|
+
sanitise: (raw: unknown) => string | null;
|
|
71
|
+
/** The sanitised string parsed back into values, for a tool or a system block. */
|
|
72
|
+
read: (context: string | null) => ContextValues<S>;
|
|
73
|
+
}
|
|
74
|
+
/** Declares a context shape once, for the page that writes it and the route that sanitises it. */
|
|
75
|
+
export declare function defineContext<S extends ContextShape>(shape: S): ContextSchema<S>;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const MAX_CONTEXT_CHARS = 4e3;
|
|
2
|
+
const MAX_ID_CHARS = 128;
|
|
3
|
+
const PATH = /^\/(?:[a-z0-9-]+(?:\/[a-z0-9-]+){0,7})?$/;
|
|
4
|
+
const isId = (pattern, value) => typeof value === "string" && value.length <= MAX_ID_CHARS && new RegExp(`^(?:${pattern.source})$`, pattern.flags.replace("g", "")).test(value);
|
|
5
|
+
function cleanField(field, value) {
|
|
6
|
+
switch (field.kind) {
|
|
7
|
+
case "path":
|
|
8
|
+
return typeof value === "string" && value.length <= 128 && PATH.test(value) ? value : void 0;
|
|
9
|
+
case "oneOf":
|
|
10
|
+
return typeof value === "string" && field.values.includes(value) ? value : void 0;
|
|
11
|
+
case "id":
|
|
12
|
+
return isId(field.pattern, value) ? value : void 0;
|
|
13
|
+
case "ids": {
|
|
14
|
+
if (!Array.isArray(value)) return void 0;
|
|
15
|
+
const kept = [...new Set(value.filter((item) => isId(field.pattern, item)))].slice(0, field.max ?? 50);
|
|
16
|
+
return kept.length ? kept : void 0;
|
|
17
|
+
}
|
|
18
|
+
case "number":
|
|
19
|
+
return typeof value === "number" && Number.isFinite(value) && (field.min === void 0 || value >= field.min) && (field.max === void 0 || value <= field.max) ? value : void 0;
|
|
20
|
+
case "flag":
|
|
21
|
+
return typeof value === "boolean" ? value : void 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function clean(shape, values) {
|
|
25
|
+
const kept = {};
|
|
26
|
+
if (typeof values !== "object" || values === null || Array.isArray(values)) return kept;
|
|
27
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
28
|
+
const value = cleanField(field, values[key]);
|
|
29
|
+
if (value !== void 0) kept[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return kept;
|
|
32
|
+
}
|
|
33
|
+
const encode = (values) => Object.keys(values).length ? JSON.stringify(values) : null;
|
|
34
|
+
function defineContext(shape) {
|
|
35
|
+
return {
|
|
36
|
+
shape,
|
|
37
|
+
write: (values) => encode(clean(shape, values)),
|
|
38
|
+
sanitise: (raw) => {
|
|
39
|
+
if (typeof raw !== "string" || raw.length > MAX_CONTEXT_CHARS) return null;
|
|
40
|
+
try {
|
|
41
|
+
return encode(clean(shape, JSON.parse(raw)));
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
read: (context) => {
|
|
47
|
+
if (!context) return {};
|
|
48
|
+
try {
|
|
49
|
+
return clean(shape, JSON.parse(context));
|
|
50
|
+
} catch {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
defineContext
|
|
58
|
+
};
|
package/chat/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { ChatWidget, type ChatWidgetProps, type ChatAgentOptions, type ChatBackd
|
|
|
18
18
|
export { useSelectionFocus, useHeldHighlight, readSelection, describeSelection, CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, type SelectedText, type DescribeSelectionOptions } from './selection';
|
|
19
19
|
export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatSelection, type SelectionKind, type SelectionLimits, type SelectionLinesOptions } from './selectionContext';
|
|
20
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';
|
|
21
|
+
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, planSequence, confirmSequence, defineContext, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, type SequenceStep, type SequencePlan, type ConfirmedStep, type ContextField, type ContextShape, type ContextValues, type ContextSchema, } from './actions';
|
|
22
22
|
export { ChatLauncher, CHAT_PANEL_ID, type ChatLauncherProps } from './ChatLauncher';
|
|
23
23
|
export { useChatAgentState } from './agentState';
|
|
24
24
|
export { ChatThreads, type ChatThreadsProps } from './ChatThreads';
|
|
@@ -39,5 +39,5 @@ export { STARTER_COUNT, pickStarters, namedStarter, hashString, mulberry32, } fr
|
|
|
39
39
|
export { greetingFor, readGreeting, serverGreeting, subscribeClock, DEFAULT_GREETING_COPY, type GreetingCopy, } from './greeting';
|
|
40
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';
|
|
41
41
|
export { artifactCard, cardArtifact } from './artifacts';
|
|
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';
|
|
42
|
+
export { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS, type ChatArtifact, type ChatCard, type ChatEvent, type ChatQuestion, type ChatQuestionAnswer, type ChatQuestionSet, type ChatPageAction, type ChatReply, type ChatTransport, type ChatTransportMessage, type ChatTurn, type ChatModelOption, type ChatFeedbackVerdict, type LivePhase, type LiveResponse, type Starter, } from './types';
|
|
43
43
|
export { chatWidget, chatWidgetRegistry, WIDGET_COUNT, type ChatWidgetMeta } from './registry';
|
package/chat/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ChatWidget } from "./ChatWidget.js";
|
|
|
3
3
|
import { CHAT_SOURCE_ATTRIBUTE, HELD_HIGHLIGHT_NAME, describeSelection, readSelection, useHeldHighlight, useSelectionFocus } from "./selection.js";
|
|
4
4
|
import { DEFAULT_SELECTION_LIMITS, sanitiseSelection, selectionLines } from "./selectionContext.js";
|
|
5
5
|
import { useGeneratedStarters } from "./generatedStarters.js";
|
|
6
|
-
import { confirmationLine, createConfirmationMark, defineAction, planAction, sanitiseConfirmation, skippedText } from "./actions.js";
|
|
6
|
+
import { confirmSequence, confirmationLine, createConfirmationMark, defineAction, planAction, planSequence, sanitiseConfirmation, skippedText } from "./actions.js";
|
|
7
7
|
import { CHAT_PANEL_ID, ChatLauncher } from "./ChatLauncher.js";
|
|
8
8
|
import { useChatAgentState } from "./agentState.js";
|
|
9
9
|
import { ChatThreads } from "./ChatThreads.js";
|
|
@@ -26,6 +26,7 @@ import { CHAT_PLACEMENTS, DOCK_MAX_WIDTH, DOCK_MIN_WIDTH, DOCK_PAGE_MIN_WIDTH, F
|
|
|
26
26
|
import { artifactCard, cardArtifact } from "./artifacts.js";
|
|
27
27
|
import { ARTIFACT_CARD_KIND, CHAT_EVENT_KINDS } from "./types.js";
|
|
28
28
|
import { WIDGET_COUNT, chatWidget, chatWidgetRegistry } from "./registry.js";
|
|
29
|
+
import { defineContext } from "./contextSchema.js";
|
|
29
30
|
export {
|
|
30
31
|
ARTIFACT_CARD_KIND,
|
|
31
32
|
ARTIFACT_MIN_COLUMN_WIDTH,
|
|
@@ -79,6 +80,7 @@ export {
|
|
|
79
80
|
chatWidget,
|
|
80
81
|
chatWidgetRegistry,
|
|
81
82
|
clampFloatPosition,
|
|
83
|
+
confirmSequence,
|
|
82
84
|
confirmationLine,
|
|
83
85
|
createConfirmationMark,
|
|
84
86
|
createFeedbackPoster,
|
|
@@ -87,6 +89,7 @@ export {
|
|
|
87
89
|
createSimTransport,
|
|
88
90
|
defaultFilesReply,
|
|
89
91
|
defineAction,
|
|
92
|
+
defineContext,
|
|
90
93
|
describeAnswers,
|
|
91
94
|
describeSelection,
|
|
92
95
|
dockFits,
|
|
@@ -103,6 +106,7 @@ export {
|
|
|
103
106
|
pickFallbackFollowups,
|
|
104
107
|
pickStarters,
|
|
105
108
|
planAction,
|
|
109
|
+
planSequence,
|
|
106
110
|
readGreeting,
|
|
107
111
|
readSelection,
|
|
108
112
|
sanitiseConfirmation,
|
package/chat/registry.json.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ declare const _default: {
|
|
|
10
10
|
"command": "init chat",
|
|
11
11
|
"subpaths": {
|
|
12
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
|
|
13
|
+
"./chat/server": "The streaming chat handler, with an opt-in tool for asking the visitor questions, the cards a reply opens with, the page actions a tool returns, 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 alone or in a sequence, the mark that says a change was confirmed on its card, and the declared shape of a page's context, with no dependencies.",
|
|
15
15
|
"./chat/upstash": "Rate limits, a daily budget and the exchange log over Upstash Redis, as the handlers' guardrails.",
|
|
16
16
|
"./chat/demo": "A scripted conversation with rich cards and fixtures, for a preview that needs no key.",
|
|
17
17
|
"./chat/chat.css": "The widget's stylesheet."
|
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, 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
|
|
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, the cards a reply opens with, the page actions a tool returns, 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 alone or in a sequence, the mark that says a change was confirmed on its card, and the declared shape of a page's context, 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
|
package/chat/server.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { default as Anthropic } from '@anthropic-ai/sdk';
|
|
2
|
-
import { ChatCard, ChatFeedbackVerdict, ChatModelOption } from './types';
|
|
2
|
+
import { ChatCard, ChatFeedbackVerdict, ChatModelOption, ChatPageAction } from './types';
|
|
3
3
|
/** What a tool hands back: text for the model, and optionally a card for the visitor. */
|
|
4
|
-
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, } from './actions';
|
|
4
|
+
export { defineAction, planAction, skippedText, createConfirmationMark, sanitiseConfirmation, confirmationLine, planSequence, confirmSequence, defineContext, type ChatAction, type ActionPlan, type ActionConfirmation, type ConfirmationMark, type SanitiseConfirmationOptions, type ConfirmationLineOptions, type SequenceStep, type SequencePlan, type ConfirmedStep, type ContextField, type ContextShape, type ContextValues, type ContextSchema, } from './actions';
|
|
5
5
|
export { sanitiseSelection, selectionLines, DEFAULT_SELECTION_LIMITS, type ChatSelection, type SelectionKind, type SelectionLimits, type SelectionLinesOptions } from './selectionContext';
|
|
6
6
|
export interface ChatToolResult {
|
|
7
7
|
/** The tool result the model reads. */
|
|
8
8
|
text: string;
|
|
9
9
|
/** Rich content streamed to the widget as a `card` event, drawn by the provider's renderers. */
|
|
10
10
|
card?: ChatCard;
|
|
11
|
+
/**
|
|
12
|
+
* Changes for the page to make in the browser, streamed as `action` events
|
|
13
|
+
* after the card and run once each by the provider's `pageActions`. An
|
|
14
|
+
* action with no `id` is given one.
|
|
15
|
+
*/
|
|
16
|
+
actions?: (Omit<ChatPageAction, 'id'> & {
|
|
17
|
+
id?: string;
|
|
18
|
+
})[];
|
|
11
19
|
}
|
|
12
20
|
/** What a tool is told about the request it runs in. */
|
|
13
21
|
export interface ChatToolContext {
|
|
@@ -179,6 +187,14 @@ export interface ChatHandlerOptions {
|
|
|
179
187
|
copy?: Partial<ChatHandlerCopy>;
|
|
180
188
|
/** Turns the request's raw `path` into context, or null to drop it. The default accepts lowercase slug paths only. */
|
|
181
189
|
sanitiseContext?: (value: unknown) => string | null;
|
|
190
|
+
/**
|
|
191
|
+
* Cards the reply opens with, sent before the model is called and marked
|
|
192
|
+
* `lead`, so they hold still under the thinking line: the record of a
|
|
193
|
+
* change the reader just confirmed, worked out from the sanitised context.
|
|
194
|
+
* Return none for a request that needs none. A failure sends no lead and
|
|
195
|
+
* the reply goes on.
|
|
196
|
+
*/
|
|
197
|
+
lead?: (context: ChatToolContext) => ChatCard[] | Promise<ChatCard[]>;
|
|
182
198
|
/** Keeps a fire-and-forget promise alive on platforms that end work with the response. */
|
|
183
199
|
waitUntil?: (promise: Promise<unknown>) => void;
|
|
184
200
|
}
|