rift-ds 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +3 -3
  2. package/behaviors/chat-card.css +135 -0
  3. package/behaviors/shell.css +119 -0
  4. package/bin/templates/blocks/components/blocks/AppShell.module.css +69 -15
  5. package/bin/templates/blocks/components/blocks/AppShell.tsx +45 -30
  6. package/bin/templates/blocks/registry.json +1 -1
  7. package/chat/AssistantTurn.js +9 -3
  8. package/chat/ChatAgentPane.css +6 -6
  9. package/chat/ChatLauncher.d.ts +3 -3
  10. package/chat/ChatLauncher.js +3 -5
  11. package/chat/ChatProvider.d.ts +10 -1
  12. package/chat/ChatProvider.js +3 -2
  13. package/chat/ChatWidget.css +272 -8
  14. package/chat/ChatWidget.d.ts +63 -9
  15. package/chat/ChatWidget.js +110 -38
  16. package/chat/DemoWelcome.js +2 -2
  17. package/chat/actions.d.ts +105 -0
  18. package/chat/actions.js +47 -0
  19. package/chat/demo-card-components.d.ts +3 -4
  20. package/chat/demo-script.js +15 -15
  21. package/chat/generatedStarters.d.ts +19 -0
  22. package/chat/generatedStarters.js +49 -0
  23. package/chat/index.d.ts +7 -3
  24. package/chat/index.js +25 -2
  25. package/chat/placement.d.ts +9 -0
  26. package/chat/placement.js +7 -0
  27. package/chat/queries.d.ts +6 -0
  28. package/chat/queries.js +25 -0
  29. package/chat/questions.d.ts +1 -1
  30. package/chat/questions.js +1 -1
  31. package/chat/registry.json.d.ts +5 -3
  32. package/chat/registry.json.js +1 -1
  33. package/chat/selection.css +8 -0
  34. package/chat/selection.d.ts +40 -0
  35. package/chat/selection.js +140 -0
  36. package/chat/selectionContext.d.ts +70 -0
  37. package/chat/selectionContext.js +60 -0
  38. package/chat/server.d.ts +54 -1
  39. package/chat/server.js +101 -5
  40. package/chat/suggestions.d.ts +12 -8
  41. package/chat/suggestions.js +1 -1
  42. package/chat/types.d.ts +2 -0
  43. package/chat/useChat.js +5 -3
  44. package/components/ActionCard/ActionCard.css +147 -0
  45. package/components/ActionCard/ActionCard.d.ts +54 -0
  46. package/components/ActionCard/ActionCard.js +75 -0
  47. package/components/ActionReadout/ActionReadout.css +47 -0
  48. package/components/ActionReadout/ActionReadout.d.ts +29 -0
  49. package/components/ActionReadout/ActionReadout.js +22 -0
  50. package/components/AgentPlan/AgentPlan.css +18 -8
  51. package/components/AgentPlan/AgentPlan.js +1 -0
  52. package/components/AppLayout/AppLayout.css +17 -4
  53. package/components/AppLayout/AppLayout.d.ts +8 -5
  54. package/components/AppLayout/AppLayout.js +2 -0
  55. package/components/AppSidebar/AppSidebar.css +119 -28
  56. package/components/AppSidebar/AppSidebar.d.ts +10 -5
  57. package/components/AppSidebar/AppSidebar.js +19 -4
  58. package/components/ArtifactCard/ArtifactCard.css +11 -10
  59. package/components/ArtifactCard/ArtifactCard.js +3 -1
  60. package/components/ChatThread/ChatThread.css +6 -3
  61. package/components/Chip/Chip.css +9 -1
  62. package/components/CodeBlock/CodeBlock.css +2 -0
  63. package/components/CodeDiff/CodeDiff.css +18 -8
  64. package/components/CodeDiff/CodeDiff.js +1 -0
  65. package/components/Composer/Composer.css +52 -13
  66. package/components/Composer/Composer.d.ts +9 -1
  67. package/components/Composer/Composer.js +19 -1
  68. package/components/DataTable/FilterEditor.js +4 -2
  69. package/components/DataTable/filterModel.d.ts +8 -0
  70. package/components/DataTable/filterModel.js +4 -0
  71. package/components/DataTable/views.js +2 -2
  72. package/components/DocumentChip/DocumentChip.css +27 -3
  73. package/components/EntitySwitcher/EntitySwitcher.css +333 -0
  74. package/components/EntitySwitcher/EntitySwitcher.d.ts +74 -0
  75. package/components/EntitySwitcher/EntitySwitcher.js +291 -0
  76. package/components/InterruptCard/InterruptCard.css +96 -34
  77. package/components/InterruptCard/InterruptCard.d.ts +20 -3
  78. package/components/InterruptCard/InterruptCard.js +23 -8
  79. package/components/MessageCard/MessageCard.css +27 -18
  80. package/components/MessageCard/MessageCard.js +1 -0
  81. package/components/PromptSuggestions/PromptSuggestions.css +3 -0
  82. package/components/Prose/Prose.css +2 -0
  83. package/components/QuestionCard/QuestionCard.css +9 -5
  84. package/components/QuestionCard/QuestionCard.js +1 -0
  85. package/components/SourceTrail/SourceTrail.css +33 -11
  86. package/components/SourceTrail/SourceTrail.js +3 -2
  87. package/components/TableToolbar/TableToolbar.css +4 -1
  88. package/components/TableToolbar/TableToolbar.js +1 -1
  89. package/components/ThemePicker/ThemePicker.css +6 -0
  90. package/components/ThemePicker/ThemePicker.js +20 -11
  91. package/components/ThreadPanel/ThreadPanel.css +65 -36
  92. package/components/ThreadPanel/ThreadPanel.d.ts +5 -5
  93. package/components/ThreadPanel/ThreadPanel.js +1 -1
  94. package/components/ToolCall/ToolCall.css +89 -22
  95. package/components/ToolCall/ToolCall.js +2 -1
  96. package/components/UsageCard/UsageCard.css +29 -2
  97. package/components/UsageCard/UsageCard.js +1 -0
  98. package/components/registry.json +25 -1
  99. package/components/registry.json.d.ts +25 -1
  100. package/components/registry.json.js +1 -1
  101. package/fonts/presets/bricolage-grotesque-300-800-latin-ext.woff2 +0 -0
  102. package/fonts/presets/bricolage-grotesque-300-800-latin.woff2 +0 -0
  103. package/fonts/presets/figtree-300-800-latin-ext.woff2 +0 -0
  104. package/fonts/presets/figtree-300-800-latin.woff2 +0 -0
  105. package/index.d.ts +3 -0
  106. package/index.js +6 -0
  107. package/package.json +5 -1
  108. package/tokens/motion.d.ts +2 -0
  109. package/tokens/motion.js +2 -0
  110. package/tokens/presets/plum.css +413 -0
  111. package/tokens/presets/presets.css +1 -0
  112. package/tokens/registry.json +2 -0
  113. package/tokens/registry.json.d.ts +2 -0
  114. package/tokens/registry.json.js +1 -1
  115. package/tokens/tokens-dark.css +6 -2
  116. package/tokens/tokens-light.css +6 -2
  117. package/tokens/tokens-typography.css +8 -2
  118. package/tokens/values.json.js +1 -1
@@ -5,6 +5,7 @@ import { AttachmentDropZone } from "../components/Attachment/AttachmentDropZone.
5
5
  import { AttachmentGroup } from "../components/Attachment/AttachmentGroup.js";
6
6
  import { useAttachments } from "../components/Attachment/useAttachments.js";
7
7
  import { ChatHeader } from "../components/ChatHeader/ChatHeader.js";
8
+ import { DocumentChip } from "../components/DocumentChip/DocumentChip.js";
8
9
  import { ChatMessage } from "../components/ChatMessage/ChatMessage.js";
9
10
  import { ChatThread } from "../components/ChatThread/ChatThread.js";
10
11
  import { CircularButton } from "../components/CircularButton/CircularButton.js";
@@ -14,7 +15,8 @@ import { DropdownMenu } from "../components/DropdownMenu/DropdownMenu.js";
14
15
  import { MentionText } from "../components/Mention/Mention.js";
15
16
  import { ModelPicker } from "../components/ModelPicker/ModelPicker.js";
16
17
  import { PromptSuggestions } from "../components/PromptSuggestions/PromptSuggestions.js";
17
- import { MOTION_SUGGESTIONS_THINK_MS, MOTION_SCROLL_SETTLE_MS } from "../tokens/motion.js";
18
+ import { MOTION_ANNOUNCE_DEBOUNCE_MS, MOTION_SUGGESTIONS_THINK_MS, MOTION_SCROLL_SETTLE_MS } from "../tokens/motion.js";
19
+ import "../behaviors/visually-hidden.css";
18
20
  import { AssistantTurn } from "./AssistantTurn.js";
19
21
  import { turnCards, cardArtifact } from "./artifacts.js";
20
22
  import { ChatAgentPane } from "./ChatAgentPane.js";
@@ -24,13 +26,14 @@ import { ChatThreads } from "./ChatThreads.js";
24
26
  import { useChatWidget, ArtifactSeatContext } from "./context.js";
25
27
  import { DEFAULT_GREETING_COPY, subscribeClock, greetingFor, serverGreeting } from "./greeting.js";
26
28
  import { CHAT_PLACEMENTS, chatPlacement } from "./placement.js";
27
- import { ASIDE_WITH_THREADS_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, THREADS_RAIL_MIN_WIDTH, ASIDE_RAIL_MIN_WIDTH } from "./queries.js";
29
+ import { ASIDE_WITH_THREADS_MIN_WIDTH, THREADS_RAIL_MIN_WIDTH, ARTIFACT_MIN_COLUMN_WIDTH, ASIDE_RAIL_MIN_WIDTH } from "./queries.js";
28
30
  import { fitsChip } from "./suggestions.js";
29
31
  import { TurnCard } from "./TurnContent.js";
30
32
  import { isBlockingQuestion } from "./questions.js";
31
33
  import { ReplyBody } from "./TurnQuestion.js";
32
34
  import { ResponseActionsLabelsContext } from "./ResponseActions.js";
33
35
  import { FollowupSuggestionsLabelContext } from "./FollowupSuggestions.js";
36
+ import "../behaviors/shell.css";
34
37
  import "./ChatWidget.css";
35
38
  import "../behaviors/direction.css";
36
39
  import { inlineSign } from "../behaviors/direction.js";
@@ -43,6 +46,8 @@ const defaultContextNote = (title) => `Looking at “${title}”`;
43
46
  const withAgentMark = (profile, title) => profile.avatar || profile.avatarSrc ? profile : { ...profile, avatar: /* @__PURE__ */ jsx(PixelAvatar, { name: title, size: "lg", label: title }) };
44
47
  function ChatWidget({
45
48
  fullscreenEnabled = true,
49
+ layout,
50
+ backdrop = "blur",
46
51
  closeEnabled = true,
47
52
  placementEnabled = false,
48
53
  compact = false,
@@ -56,6 +61,7 @@ function ChatWidget({
56
61
  tagline = "How can I help you today?",
57
62
  starters: startersInput,
58
63
  startersKey = "",
64
+ startersPending = false,
59
65
  composerActions,
60
66
  models,
61
67
  defaultModel,
@@ -70,9 +76,11 @@ function ChatWidget({
70
76
  aside,
71
77
  agent,
72
78
  artifacts = false,
79
+ context: contextProp,
80
+ contextClearLabel = "Clear context",
73
81
  contextLabel,
74
82
  contextNote = defaultContextNote,
75
- contextPlacement = "above",
83
+ contextPlacement = "inside",
76
84
  attachHint: attachHintText = defaultAttachHint,
77
85
  greetings,
78
86
  placementLabels,
@@ -176,7 +184,7 @@ function ChatWidget({
176
184
  const lockedValues = modelPolicy?.locked ?? [];
177
185
  const pick = chosenModel && !lockedValues.includes(chosenModel) ? chosenModel : null;
178
186
  const pickerValue = pick ?? modelPolicy?.default ?? defaultModel ?? models?.[0]?.value;
179
- const composerHasActions = fileAttachments || Boolean(composerActions) || (models?.length ?? 0) > 0 || Boolean(contextLabel) && contextPlacement === "inside";
187
+ const composerHasActions = fileAttachments || Boolean(composerActions) || (models?.length ?? 0) > 0;
180
188
  const pickerModels = (models ?? []).map((option) => ({
181
189
  value: option.value,
182
190
  label: option.label,
@@ -197,29 +205,55 @@ function ChatWidget({
197
205
  }, [open]);
198
206
  const queue = useAttachments({ maxCount: maxAttachments, maxSize: maxAttachmentBytes });
199
207
  const attachHint = attachHintText(formatBytes(maxAttachmentBytes), maxAttachments, maxAttachmentBytes);
208
+ const context = contextProp ?? (contextLabel ? { label: contextLabel, note: contextNote(contextLabel) } : null);
209
+ const contextIcon = context?.icon ?? "description";
210
+ const contextNoteText = context ? context.note ?? defaultContextNote(context.label) : "";
211
+ const [announcedContext, setAnnouncedContext] = useState("");
212
+ const openingContext = useRef(contextNoteText);
213
+ useEffect(() => {
214
+ if (contextNoteText === openingContext.current) return;
215
+ openingContext.current = "";
216
+ const timer = setTimeout(() => setAnnouncedContext(contextNoteText), MOTION_ANNOUNCE_DEBOUNCE_MS);
217
+ return () => clearTimeout(timer);
218
+ }, [contextNoteText]);
219
+ const sentContext = () => {
220
+ if (!context?.sent) return void 0;
221
+ if (typeof context.sent === "function") return context.sent();
222
+ return /* @__PURE__ */ jsx("div", { className: "ds-chat-widget__sent-context", children: /* @__PURE__ */ jsx(DocumentChip, { size: "compact", name: context.label, icon: contextIcon }) });
223
+ };
200
224
  const handleSubmit = (value) => {
201
225
  if (fileAttachments && queue.items.length > 0) {
202
226
  const ready = queue.items.filter((item) => item.status === "ready");
203
- if (send(value, { attachments: ready })) {
227
+ if (send(value, { attachments: ready, content: sentContext() })) {
204
228
  queue.take();
205
229
  setDraft("");
206
230
  }
207
- } else if (send(value)) setDraft("");
231
+ } else if (send(value, { content: sentContext() })) setDraft("");
208
232
  focusComposer();
209
233
  };
210
234
  const isFull = view === "full";
211
235
  const isEmpty = turns.length === 0 && !live;
212
236
  const [stagedKey, setStagedKey] = useState(null);
213
- const startersThinking = open && isEmpty && starterRevealKey !== startersKey;
237
+ const heldKey = useRef(null);
238
+ const startersThinking = open && isEmpty && (startersPending || starterRevealKey !== startersKey);
214
239
  const startersEntrance = startersThinking || stagedKey === startersKey;
215
240
  useEffect(() => {
216
241
  if (!(open && isEmpty && starterRevealKey !== startersKey)) return;
217
- const timer = setTimeout(() => {
242
+ if (startersPending) {
243
+ heldKey.current = startersKey;
244
+ return;
245
+ }
246
+ const reveal = () => {
218
247
  setStagedKey(startersKey);
219
248
  setStarterRevealKey(startersKey);
220
- }, MOTION_SUGGESTIONS_THINK_MS);
249
+ };
250
+ if (heldKey.current === startersKey) {
251
+ reveal();
252
+ return;
253
+ }
254
+ const timer = setTimeout(reveal, MOTION_SUGGESTIONS_THINK_MS);
221
255
  return () => clearTimeout(timer);
222
- }, [open, isEmpty, starterRevealKey, setStarterRevealKey, startersKey]);
256
+ }, [open, isEmpty, starterRevealKey, setStarterRevealKey, startersKey, startersPending]);
223
257
  const renderThreads = threads === true ? (ctx) => /* @__PURE__ */ jsx(ChatThreads, { ...threadsProps, logoText: threadsProps?.logoText ?? title, ...ctx }) : threads || void 0;
224
258
  const renderAside = aside ?? (agent ? (ctx) => /* @__PURE__ */ jsx(
225
259
  ChatAgentPane,
@@ -269,6 +303,17 @@ function ChatWidget({
269
303
  return () => observer.disconnect();
270
304
  }, [hasRails, closeArtifact]);
271
305
  const closeThreads = () => setThreadsOpen(false);
306
+ const [shellNarrow, setShellNarrow] = useState(false);
307
+ useEffect(() => {
308
+ if (!layout || layout === "flush") return;
309
+ const host = railsHostRef.current ?? composerRef.current?.closest(".ds-chat-widget");
310
+ if (!host) return;
311
+ const measure = () => setShellNarrow(host.clientWidth < THREADS_RAIL_MIN_WIDTH);
312
+ measure();
313
+ const observer = new ResizeObserver(measure);
314
+ observer.observe(host);
315
+ return () => observer.disconnect();
316
+ }, [layout, hasRails]);
272
317
  const artifactId = useId();
273
318
  const artifactShown = artifacts && (artifact !== null || artifactEmptyOpen);
274
319
  const [heldArtifact, setHeldArtifact] = useState(artifact);
@@ -340,6 +385,23 @@ function ChatWidget({
340
385
  }, [artifacts, turns, openArtifact]);
341
386
  const trailingUp = artifactInline || Boolean(renderAside) && asideOpen && asideWide;
342
387
  const threadsInline = threadsWide && !(trailingUp && (!asideRoomy || artifactExpanded));
388
+ useEffect(() => {
389
+ if (!artifacts) return;
390
+ const host = railsHostRef.current;
391
+ if (!host) return;
392
+ const measure = () => {
393
+ const threadsRail2 = host.querySelector(":scope > .ds-chat-widget__threads-rail");
394
+ const inset = parseFloat(getComputedStyle(host).getPropertyValue("--ds-chat-artifact-inset")) || 0;
395
+ const room = host.clientWidth - (threadsRail2?.offsetWidth ?? 0) - ARTIFACT_MIN_COLUMN_WIDTH - inset * 2;
396
+ host.style.setProperty("--ds-chat-artifact-room", `${Math.max(0, Math.round(room))}px`);
397
+ };
398
+ measure();
399
+ const observer = new ResizeObserver(measure);
400
+ observer.observe(host);
401
+ const threadsRail = host.querySelector(":scope > .ds-chat-widget__threads-rail");
402
+ if (threadsRail) observer.observe(threadsRail);
403
+ return () => observer.disconnect();
404
+ }, [artifacts, threadsInline]);
343
405
  const asideRailRef = useRef(null);
344
406
  const asideMounted = Boolean(renderAside) && asideWide;
345
407
  useEffect(() => {
@@ -379,7 +441,7 @@ function ChatWidget({
379
441
  suggestions: starters,
380
442
  onValueChange: (id) => {
381
443
  const starter = starters.find((s) => s.id === id);
382
- if (starter && send(starter.label)) focusComposer();
444
+ if (starter && send(starter.label, { content: sentContext() })) focusComposer();
383
445
  }
384
446
  }
385
447
  ) });
@@ -493,10 +555,14 @@ function ChatWidget({
493
555
  rootSettleTimer.current = window.setTimeout(() => setRootScrolling(false), MOTION_SCROLL_SETTLE_MS);
494
556
  };
495
557
  useEffect(() => () => window.clearTimeout(rootSettleTimer.current), []);
558
+ const shellMode = layout && layout !== "flush" && shellNarrow ? "flush" : layout;
559
+ const shellBackdrop = shellMode === layout ? backdrop : "solid";
560
+ const shellAttrs = shellMode ? { "data-ds-shell": shellMode, "data-ds-shell-backdrop": shellMode === "flush" ? shellBackdrop : void 0 } : {};
496
561
  const chatColumn = /* @__PURE__ */ jsxs(
497
562
  ChatRoot,
498
563
  {
499
564
  ...dropProps,
565
+ ...hasRails ? {} : shellAttrs,
500
566
  className: `ds-chat-widget ${renderThreads ? "ds-chat-widget--with-threads" : ""}`,
501
567
  "data-compact": compact || void 0,
502
568
  "data-phone": phone || void 0,
@@ -561,31 +627,34 @@ function ChatWidget({
561
627
  ),
562
628
  tabsNode && /* @__PURE__ */ jsx("div", { className: "ds-chat-widget__tabs-row", children: tabsNode }),
563
629
  /* @__PURE__ */ jsxs("div", { className: "ds-chat-widget__body", children: [
564
- /* @__PURE__ */ jsx(ArtifactSeatContext.Provider, { value: artifacts, children: /* @__PURE__ */ jsx(ResponseActionsLabelsContext.Provider, { value: responseActionsLabels, children: /* @__PURE__ */ jsx(FollowupSuggestionsLabelContext.Provider, { value: followupsLabel, children: /* @__PURE__ */ jsx(ChatThread, { ...chatThreadLabels, className: "ds-chat-widget__thread", flow, children: [
565
- ...turns.map(
566
- (turn) => turn.bare ? (
567
- /* Conversation furniture (a day marker): the injected
568
- content stands alone in the thread, no message chrome. */
569
- /* @__PURE__ */ jsx("div", { children: turn.content }, turn.id)
570
- ) : turn.role === "user" ? (
571
- /* Files ride above the bubble on the sender's side; a turn
572
- of files alone draws no bubble. */
573
- /* @__PURE__ */ jsx(
574
- ChatMessage,
575
- {
576
- role: "user",
577
- attachments: turn.attachments ? /* @__PURE__ */ jsx(AttachmentGroup, { ...attachmentGroupLabels, align: "end", items: turn.attachments }) : /* @__PURE__ */ jsxs(Fragment, { children: [
578
- turn.content,
579
- turnCards(turn).map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index))
580
- ] }),
581
- children: turn.reply ? /* @__PURE__ */ jsx(ReplyBody, { reply: turn.reply, text: turn.text, missingLabel: questionSummaryLabels?.missingLabel }) : mentions && turn.text ? /* @__PURE__ */ jsx(MentionText, { text: turn.text, sources: mentions }) : turn.text
582
- },
583
- turn.id
584
- )
585
- ) : /* @__PURE__ */ jsx(AssistantTurn, { turn, labels: turnLabels }, turn.id)
586
- ),
587
- ...live ? [/* @__PURE__ */ jsx(AssistantTurn, { live, labels: turnLabels }, live.id)] : []
588
- ] }) }) }) }),
630
+ /* @__PURE__ */ jsx(ArtifactSeatContext.Provider, { value: artifacts, children: /* @__PURE__ */ jsx(ResponseActionsLabelsContext.Provider, { value: responseActionsLabels, children: /* @__PURE__ */ jsxs(FollowupSuggestionsLabelContext.Provider, { value: followupsLabel, children: [
631
+ /* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", "aria-live": "polite", children: open ? announcedContext : "" }),
632
+ /* @__PURE__ */ jsx(ChatThread, { ...chatThreadLabels, className: "ds-chat-widget__thread", flow, children: [
633
+ ...turns.map(
634
+ (turn) => turn.bare ? (
635
+ /* Conversation furniture (a day marker): the injected
636
+ content stands alone in the thread, no message chrome. */
637
+ /* @__PURE__ */ jsx("div", { children: turn.content }, turn.id)
638
+ ) : turn.role === "user" ? (
639
+ /* Files ride above the bubble on the sender's side; a turn
640
+ of files alone draws no bubble. */
641
+ /* @__PURE__ */ jsx(
642
+ ChatMessage,
643
+ {
644
+ role: "user",
645
+ attachments: turn.attachments ? /* @__PURE__ */ jsx(AttachmentGroup, { ...attachmentGroupLabels, align: "end", items: turn.attachments }) : /* @__PURE__ */ jsxs(Fragment, { children: [
646
+ turn.content,
647
+ turnCards(turn).map((card, index) => /* @__PURE__ */ jsx(TurnCard, { card }, index))
648
+ ] }),
649
+ children: turn.reply ? /* @__PURE__ */ jsx(ReplyBody, { reply: turn.reply, text: turn.text, missingLabel: questionSummaryLabels?.missingLabel }) : mentions && turn.text ? /* @__PURE__ */ jsx(MentionText, { text: turn.text, sources: mentions }) : turn.text
650
+ },
651
+ turn.id
652
+ )
653
+ ) : /* @__PURE__ */ jsx(AssistantTurn, { turn, labels: turnLabels }, turn.id)
654
+ ),
655
+ ...live ? [/* @__PURE__ */ jsx(AssistantTurn, { live, labels: turnLabels }, live.id)] : []
656
+ ] })
657
+ ] }) }) }),
589
658
  isEmpty && /* @__PURE__ */ jsx("div", { className: "ds-chat-widget__welcome", children: /* @__PURE__ */ jsxs("div", { className: "ds-chat-widget__greeting", children: [
590
659
  /* @__PURE__ */ jsx("p", { className: "ds-chat-widget__hello", children: greeting }),
591
660
  /* @__PURE__ */ jsx("p", { className: "ds-chat-widget__ask", children: tagline })
@@ -609,9 +678,11 @@ function ChatWidget({
609
678
  onSubmit: handleSubmit,
610
679
  streaming,
611
680
  onStop: stop,
612
- context: contextLabel ? contextNote(contextLabel) : void 0,
613
- contextIcon: "description",
681
+ context: context ? context.note ?? defaultContextNote(context.label) : void 0,
682
+ contextIcon,
614
683
  contextPlacement,
684
+ onContextClear: context?.onClear,
685
+ contextClearLabel,
615
686
  mentions,
616
687
  ...fileAttachments ? {
617
688
  files: queue.items,
@@ -660,6 +731,7 @@ function ChatWidget({
660
731
  {
661
732
  ref: railsHostRef,
662
733
  className: "ds-chat-widget__rails",
734
+ ...shellAttrs,
663
735
  "data-artifact-expanded": artifactExpanded || void 0,
664
736
  "data-artifact-sized": artifactWidth !== null || artifactResizing || void 0,
665
737
  "data-artifact-resizing": artifactResizing || void 0,
@@ -9,7 +9,7 @@ import { WidgetGrid, Widget, WidgetRow, WidgetGroup } from "../components/Widget
9
9
  const LINKS = [
10
10
  { id: "How do I get started?", icon: "rocket_launch", label: "Get started", description: "Set up a workspace" },
11
11
  { id: "What do the plans include?", icon: "sell", label: "Plans", description: "What each one includes" },
12
- { id: "Invite my team to a workspace", icon: "group_add", label: "Team", description: "Invite the others" },
12
+ { id: "Invite my team", icon: "group_add", label: "Team", description: "Invite the others" },
13
13
  { id: "How is the trial going?", icon: "monitoring", label: "Trial", description: "Signups so far" }
14
14
  ];
15
15
  const CARDS = [
@@ -70,7 +70,7 @@ function DemoBoard({ onAsk }) {
70
70
  title: "Invite the other three",
71
71
  description: "2 of 5 seats filled",
72
72
  meta: "Today",
73
- onClick: () => onAsk("Invite my team to a workspace")
73
+ onClick: () => onAsk("Invite my team")
74
74
  }
75
75
  ),
76
76
  /* @__PURE__ */ jsx(
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Changes a chat can propose and a reader confirms, defined once.
3
+ *
4
+ * An action says which records it applies to (`skip` gives the reason it
5
+ * leaves one alone, or null), what it writes to each (`apply`), and the words
6
+ * around it: its button and card title (`label`), what a receipt says was
7
+ * done (`done`), the reader's words when they confirm it in the chat
8
+ * (`confirm`), and how a page's own confirmation asks (`verb`, `effect`). The
9
+ * same definition drives a selection bar's button and the chat's proposal, so
10
+ * the two can never do different things to the same records. `planAction` is
11
+ * the dry run both show before anything changes.
12
+ *
13
+ * Pure and framework-free: published on its own as rift-ds/chat/actions, so a
14
+ * shared definitions module pulls in no peer, and re-exported from
15
+ * rift-ds/chat for the page and rift-ds/chat/server for the route that
16
+ * proposes, which plans the same action over the same records. The flow it
17
+ * serves (propose on a card, the reader's Confirm sent as their message, the
18
+ * reply opening with a readout) is design.md's "A chat proposes, the reader
19
+ * confirms".
20
+ *
21
+ * The confirmation mark is what makes that flow safe. The reader's Confirm
22
+ * sends their words as an ordinary message, which they could also type, so
23
+ * the words alone can never be what tells the server a change was made. The
24
+ * page marks the one request its Confirm sends (`createConfirmationMark`),
25
+ * the route rebuilds the mark from the request (`sanitiseConfirmation`), and
26
+ * the model is told whether this message was confirmed on its card
27
+ * (`confirmationLine`). A typed "yes, cancel them" carries no mark.
28
+ */
29
+ export interface ChatAction<Values, Edit = Partial<Values>> {
30
+ /** A stable id the server and the page share. */
31
+ id: string;
32
+ /** The button's words, and the proposal card's title: "Cancel orders". */
33
+ label: string;
34
+ /** What a receipt says was done, after the count: "cancelled". */
35
+ done: string;
36
+ /** The reader's words when they confirm it in the chat, given "this order" or "these 23 orders". */
37
+ confirm: (these: string) => string;
38
+ /** The verb a confirmation asks with: "Cancel" in "Cancel 3 orders?", and on its confirm button. Defaults to the label. */
39
+ verb?: string;
40
+ /** What the change does to the records, for a confirmation's body, given how many it changes: "Any that were paid are refunded." Worded for the count, so one record reads as one. */
41
+ effect?: (count: number) => string;
42
+ /** A Material Symbol for the card and the button. */
43
+ icon: string;
44
+ /** Drawn as destructive on the card and the bar. */
45
+ destructive?: boolean;
46
+ /** Why a record is left alone ("already shipped"), or null when the action applies to it. */
47
+ skip: (values: Values) => string | null;
48
+ /** What the action writes to a record it applies to. */
49
+ apply: (values: Values) => Edit;
50
+ }
51
+ /** Declares an action, typed by the records it acts on. */
52
+ export declare const defineAction: <Values, Edit = Partial<Values>>(action: ChatAction<Values, Edit>) => ChatAction<Values, Edit>;
53
+ /** What an action would do to some records: the ones it changes, and how many it leaves alone for each reason. */
54
+ export interface ActionPlan {
55
+ action: string;
56
+ ids: string[];
57
+ skipped: Record<string, number>;
58
+ }
59
+ /** The dry run: which of these records the action changes, and why it leaves the rest. Changes nothing. */
60
+ export declare function planAction<Values>(action: ChatAction<Values, unknown>, records: {
61
+ id: string;
62
+ values: Values;
63
+ }[]): ActionPlan;
64
+ /** A change the reader confirmed on its card: which action, how many records it changed, and their ids. */
65
+ export interface ActionConfirmation<Id extends string = string> {
66
+ action: Id;
67
+ count: number;
68
+ ids: string[];
69
+ }
70
+ /** The page's one-shot mark: set on Confirm, read once by the next request, then gone. */
71
+ export interface ConfirmationMark<Id extends string = string> {
72
+ /** Marks the request about to carry the reader's confirmation. */
73
+ mark: (confirmation: ActionConfirmation<Id>) => void;
74
+ /** The mark for this request, cleared as it is read, or null when the message was not a card's Confirm. */
75
+ take: () => ActionConfirmation<Id> | null;
76
+ }
77
+ /** A holder for the confirmation mark. Keep one per chat (a ref or a module value); the transport calls `take` in `getContext`. */
78
+ export declare function createConfirmationMark<Id extends string = string>(): ConfirmationMark<Id>;
79
+ export interface SanitiseConfirmationOptions {
80
+ /** The actions a confirmation may name, by id. */
81
+ actions: Record<string, ChatAction<never, unknown>> | readonly string[];
82
+ /** Whether an id is a real record. Ids that are not are dropped. */
83
+ isId: (id: string) => boolean;
84
+ /** The most records one confirmation can change. */
85
+ maxCount: number;
86
+ /** The most ids kept. Defaults to 50. */
87
+ maxIds?: number;
88
+ }
89
+ /** The confirmation a request claims, rebuilt as untrusted input: a known action, a count in range, real ids only. Null for none. */
90
+ export declare function sanitiseConfirmation(value: unknown, { actions, isId, maxCount, maxIds }: SanitiseConfirmationOptions): ActionConfirmation | null;
91
+ export interface ConfirmationLineOptions {
92
+ /** The actions a confirmation may name, by id, for the words that say what was done. */
93
+ 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;
96
+ /** The locale the count is written in. */
97
+ locale?: string;
98
+ }
99
+ /**
100
+ * The line that tells the model whether this message was a card's Confirm, so
101
+ * it says a change is made only when it was.
102
+ */
103
+ export declare function confirmationLine(confirmation: ActionConfirmation | null, { actions, noun, locale }: ConfirmationLineOptions): string;
104
+ /** "2 already shipped, 1 cancelled": the records a plan leaves alone, in words, its counts in `locale`. */
105
+ export declare const skippedText: (skipped: Record<string, number>, locale?: string) => string;
@@ -0,0 +1,47 @@
1
+ import { DEFAULT_LOCALE } from "../behaviors/locale.js";
2
+ const defineAction = (action) => action;
3
+ function planAction(action, records) {
4
+ const ids = [];
5
+ const skipped = {};
6
+ for (const record of records) {
7
+ const reason = action.skip(record.values);
8
+ if (reason) skipped[reason] = (skipped[reason] ?? 0) + 1;
9
+ else ids.push(record.id);
10
+ }
11
+ return { action: action.id, ids, skipped };
12
+ }
13
+ function createConfirmationMark() {
14
+ let pending = null;
15
+ return {
16
+ mark: (confirmation) => {
17
+ pending = confirmation;
18
+ },
19
+ take: () => {
20
+ const confirmation = pending;
21
+ pending = null;
22
+ return confirmation;
23
+ }
24
+ };
25
+ }
26
+ function sanitiseConfirmation(value, { actions, isId, maxCount, maxIds = 50 }) {
27
+ const { action, count, ids } = value ?? {};
28
+ const known = Array.isArray(actions) ? actions : Object.keys(actions);
29
+ if (typeof action !== "string" || !known.includes(action)) return null;
30
+ if (typeof count !== "number" || !Number.isFinite(count) || count < 1 || count > maxCount) return null;
31
+ const kept = Array.isArray(ids) ? ids.filter((id) => typeof id === "string" && isId(id)) : [];
32
+ return { action, count: Math.floor(count), ids: [...new Set(kept)].slice(0, maxIds) };
33
+ }
34
+ function confirmationLine(confirmation, { actions, noun, locale = DEFAULT_LOCALE }) {
35
+ const action = confirmation ? actions[confirmation.action] : void 0;
36
+ if (!confirmation || !action) return "This message was not confirmed on a card. Nothing it says has changed anything.";
37
+ return `This message was confirmed on its card: ${confirmation.count.toLocaleString(locale)} ${noun(confirmation.count)} ${action.done}. The change is made.`;
38
+ }
39
+ const skippedText = (skipped, locale = DEFAULT_LOCALE) => Object.entries(skipped).map(([reason, count]) => `${count.toLocaleString(locale)} ${reason}`).join(", ");
40
+ export {
41
+ confirmationLine,
42
+ createConfirmationMark,
43
+ defineAction,
44
+ planAction,
45
+ sanitiseConfirmation,
46
+ skippedText
47
+ };
@@ -1,3 +1,4 @@
1
+ import { InterruptCardOption } from '../components/InterruptCard/InterruptCard';
1
2
  import { ChatCardRenderers } from './context';
2
3
  import { ChatCard } from './types';
3
4
  export interface DemoChartCard {
@@ -21,11 +22,9 @@ export interface DemoToolCallCard {
21
22
  export interface DemoInterruptCard {
22
23
  title: string;
23
24
  description: string;
24
- options: {
25
- value: string;
26
- label: string;
25
+ options: (Pick<InterruptCardOption, 'value' | 'label' | 'answeredLabel' | 'answeredVariant'> & {
27
26
  variant: 'primary' | 'secondary';
28
- }[];
27
+ })[];
29
28
  }
30
29
  /** Several cards landing as one turn's stack. */
31
30
  export interface DemoStackCard {
@@ -32,7 +32,7 @@ function planFor(answer) {
32
32
  return {
33
33
  steps: [{ status: "Matching the plan", point: "Team size decides the plan; nothing else differs." }],
34
34
  text: `For ${answer.trim().replace(/[.!?]$/, "")}, ${plan}.`,
35
- followups: ["What do the plans include?", "Invite my team to a workspace", "Set up notifications for me"]
35
+ followups: ["What do the plans include?", "Invite my team", "Set up notifications for me"]
36
36
  };
37
37
  }
38
38
  const INVITES_SENT = {
@@ -56,12 +56,12 @@ const PLANS_COMPARED = {
56
56
  { status: "Drafting the answer", point: "Name what the Team plan adds over the base." }
57
57
  ],
58
58
  text: "Every plan includes unlimited projects. The Team plan adds shared workspaces, guest seats, and a 90 day version history.",
59
- followups: ["Which plan fits a team of five?", "Help me pick a plan", "Where is that written down?"]
59
+ followups: ["Which plan fits five people?", "Help me pick a plan", "Where is that written down?"]
60
60
  };
61
61
  const DEMO_STARTERS = [
62
62
  { id: "start", label: "How do I get started?" },
63
63
  { id: "plans", label: "What do the plans include?" },
64
- { id: "invite", label: "Invite my team to a workspace" }
64
+ { id: "invite", label: "Invite my team" }
65
65
  ];
66
66
  const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
67
67
  "Create a workspace from the dashboard, then invite your team from Settings. Everyone you add sees the shared projects the moment they join. If you would rather not click through it, I can set the whole thing up for you.",
@@ -79,7 +79,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
79
79
  ],
80
80
  card: card("plan", { steps: PLAN_STEPS }),
81
81
  followups: ["Find a time we can all meet", "Take us up to twelve seats", "How is the trial going?"]
82
- }).user("What do the plans include?").assistant(PLANS_COMPARED.text, PLANS_COMPARED).user("Which plan fits a team of five?").assistant("The Team plan fits what you described: shared workspaces for the whole team, and guest seats stay free. Shall we go with it?", {
82
+ }).user("What do the plans include?").assistant(PLANS_COMPARED.text, PLANS_COMPARED).user("Which plan fits five people?").assistant("The Team plan fits what you described: shared workspaces for the whole team, and guest seats stay free. Shall we go with it?", {
83
83
  steps: [
84
84
  { status: "Matching plans to the team", point: "The visitor needs shared workspaces and guest seats." },
85
85
  { status: "Drafting the answer", point: "The Team plan covers both; lead with the card." }
@@ -105,7 +105,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
105
105
  answered: (answer) => answer.toLowerCase().includes("compare") ? PLANS_COMPARED : {
106
106
  steps: [{ status: "Switching the plan", point: "Move the workspace to Team from today." }],
107
107
  text: "Done. The workspace is on the Team plan from today, billed monthly, and you can step back down any time.",
108
- followups: ["Invite my team to a workspace", "Where is that written down?", "How is the trial going?"]
108
+ followups: ["Invite my team", "Where is that written down?", "How is the trial going?"]
109
109
  }
110
110
  }).user("Where is that written down?").assistant("Each chip opens the page the answer came from, so nothing here needs taking on trust.", {
111
111
  steps: [
@@ -137,7 +137,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
137
137
  }
138
138
  ]
139
139
  }),
140
- followups: ["Which plan fits a team of five?", "How do I get started?", "How is the trial going?"]
140
+ followups: ["Which plan fits five people?", "How do I get started?", "How is the trial going?"]
141
141
  }).user("How is the trial going?").assistant("Signups have climbed for five of the six weeks since the trial opened, and last week was the strongest yet.", {
142
142
  steps: [
143
143
  { status: "Pulling the signup numbers", point: "Six weeks of signup data since the trial opened." },
@@ -152,8 +152,8 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
152
152
  yKey: "signups",
153
153
  label: "Signups"
154
154
  }),
155
- followups: ["Which plan fits a team of five?", "Invite my team to a workspace", "Where is that written down?"]
156
- }).user("Invite my team to a workspace").assistant("Happy to. Shall I send invites to the three teammates on your account, all as editors?", {
155
+ followups: ["Which plan fits five people?", "Invite my team", "Where is that written down?"]
156
+ }).user("Invite my team").assistant("Happy to. Shall I send invites to the three teammates on your account, all as editors?", {
157
157
  steps: [
158
158
  { status: "Checking the account", point: "Three teammates sit on the account, none invited yet." },
159
159
  { status: "Drafting the answer", point: "Confirm before sending anything." }
@@ -176,7 +176,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
176
176
  text: "Nothing sent. The three are ready to go whenever you are.",
177
177
  followups: ["Take us up to twelve seats", "Find a time we can all meet", "How is the trial going?"]
178
178
  } : INVITES_SENT
179
- }).user("Go ahead and invite the other three").assistant(INVITES_SENT.text, INVITES_SENT).user("Take us up to twelve seats").assistant("Only the seat count moves, from five to twelve. Everything else in the config stays as it was. Apply it?", {
179
+ }).user("Invite the other three").assistant(INVITES_SENT.text, INVITES_SENT).user("Take us up to twelve seats").assistant("Only the seat count moves, from five to twelve. Everything else in the config stays as it was. Apply it?", {
180
180
  steps: [
181
181
  { status: "Locating the seat limit", point: "The seat limit lives in workspace.config.ts." },
182
182
  { status: "Preparing the change", point: "One line changes; show the diff." }
@@ -201,7 +201,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
201
201
  answered: (answer) => answer.toLowerCase().startsWith("not yet") ? {
202
202
  steps: [{ status: "Leaving the config", point: "The diff stays a proposal." }],
203
203
  text: "Left as it is. The workspace stays at five seats until you say otherwise.",
204
- followups: ["What do the plans include?", "Invite my team to a workspace", "How is the trial going?"]
204
+ followups: ["What do the plans include?", "Invite my team", "How is the trial going?"]
205
205
  } : {
206
206
  steps: [{ status: "Applying the change", point: "One line in workspace.config.ts." }],
207
207
  text: "Applied. The workspace takes twelve seats from now, and the next invoice picks up the difference.",
@@ -211,7 +211,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
211
211
  status: "success",
212
212
  duration: "0.4s"
213
213
  }),
214
- followups: ["Invite my team to a workspace", "Find a time we can all meet", "How is the trial going?"]
214
+ followups: ["Invite my team", "Find a time we can all meet", "How is the trial going?"]
215
215
  }
216
216
  }).user("Here is the launch plan we are working from.").assistant(
217
217
  "Three phases, and most of the budget sits behind launch week itself. The dates line up with the workspace you already set up, so nothing needs to move.",
@@ -265,7 +265,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
265
265
  answered: (answer) => answer.toLowerCase().startsWith("leave") ? {
266
266
  steps: [{ status: "Leaving the sync", point: "Nothing to retry until asked." }],
267
267
  text: "Left for now. Nothing else depends on it, and it can run again whenever you like.",
268
- followups: ["Find a time we can all meet", "Invite my team to a workspace", "How is the trial going?"]
268
+ followups: ["Find a time we can all meet", "Invite my team", "How is the trial going?"]
269
269
  } : {
270
270
  steps: [{ status: "Retrying the sync", point: "Second attempt against the provider." }],
271
271
  text: "Second time lucky. The shared calendar is in sync.",
@@ -299,14 +299,14 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
299
299
  answered: (answer) => answer.toLowerCase().startsWith("not now") ? {
300
300
  steps: [{ status: "Leaving the calendar alone", point: "No access; offer the manual route." }],
301
301
  text: "No problem, nothing is connected. You can share a few times that suit you and I will send them round.",
302
- followups: ["Go ahead and invite the other three", "How is the trial going?", "How do I get started?"]
302
+ followups: ["Invite the other three", "How is the trial going?", "How do I get started?"]
303
303
  } : {
304
304
  steps: [
305
305
  { status: "Reading the shared calendar", point: "Four calendars, the next ten working days." },
306
306
  { status: "Finding a free slot", point: "Thursday afternoon is clear for everyone." }
307
307
  ],
308
308
  text: answer.toLowerCase().includes("always") ? "Connected for good. Thursday at 2pm is the first slot everyone has free, and I will keep an eye out when plans change." : "Read once and disconnected. Thursday at 2pm is the first slot everyone has free.",
309
- followups: ["Plan our launch kickoff", "Go ahead and invite the other three", "How is the trial going?"]
309
+ followups: ["Plan our launch kickoff", "Invite the other three", "How is the trial going?"]
310
310
  }
311
311
  }).user("Build me a launch dashboard").assistant(
312
312
  "Here is the launch on one board: what is running now, the trial signups, the projects and what is waiting on you. The rows that ask a question will ask it here.",
@@ -316,7 +316,7 @@ const DEMO_SCRIPT = scriptChat().user("How do I get started?").assistant(
316
316
  { status: "Laying out the dashboard", point: "Too much for a card; build it as an artifact." }
317
317
  ],
318
318
  card: artifactCard(DEMO_DASHBOARD_ARTIFACT),
319
- followups: ["Draft the launch page", "How is the trial going?", "Which plan fits a team of five?"]
319
+ followups: ["Draft the launch page", "How is the trial going?", "Which plan fits five people?"]
320
320
  }
321
321
  ).user("Draft the launch page").assistant(
322
322
  "A first draft of the launch page is up beside the chat: the headline, the three things the Team plan adds, and one call to action. The source is behind the Code view.",
@@ -0,0 +1,19 @@
1
+ import { Starter } from './types';
2
+ export interface GeneratedStartersOptions {
3
+ /** The route `createStartersHandler` serves. */
4
+ endpoint: string;
5
+ /** Ask only while this is true: the welcome screen is showing. */
6
+ active: boolean;
7
+ /** The written chips for when nothing comes back, and while the model writes. */
8
+ fallback: Starter[];
9
+ }
10
+ export interface GeneratedStarters {
11
+ /** The chips to show: the model's once written, the fallback until then. Null with no request. */
12
+ starters: Starter[] | null;
13
+ /** Whether the model is still writing them: ChatWidget's `startersPending`. */
14
+ pending: boolean;
15
+ /** A short, stable key for the request: ChatWidget's `startersKey`. */
16
+ key: string | null;
17
+ }
18
+ /** The model's starters for `request`, or null for none (the host shows its own). */
19
+ export declare function useGeneratedStarters(request: string | null, { endpoint, active, fallback }: GeneratedStartersOptions): GeneratedStarters;