The Open Standard for Generative UI
refactor(react-ui): rename the prefill-chips welcome API to prompt templates (#836)
Ankit Das5e6417b747b3
diff --git a/packages/react-ui/src/components/AgentInterface/WelcomeScreen.tsx b/packages/react-ui/src/components/AgentInterface/WelcomeScreen.tsxindex 9e0046230..40f79ccd9 100644--- a/packages/react-ui/src/components/AgentInterface/WelcomeScreen.tsx+++ b/packages/react-ui/src/components/AgentInterface/WelcomeScreen.tsx@@ -2,7 +2,7 @@ import { useThread, useThreadList } from "@openuidev/react-headless";import clsx from "clsx";import { ReactNode, useEffect, useRef, useState } from "react";import { ConversationStarterProps } from "../../types/ConversationStarter";-import { PrefillChip } from "../../types/PrefillChip";+import { PromptTemplate } from "../../types/PromptTemplate";import { useStartersFromContext } from "./_shared/startersContext";import { isChatEmpty } from "./_shared/utils";import { appendStarterPrompt } from "./_shared/utils/welcomePrefill";@@ -46,11 +46,12 @@ interface WelcomeScreenWithContentProps extends WelcomeScreenBaseProps {*/starterVariant?: ConversationStarterVariant;/**- * Prefill chips rendered between the composer and the starters. Clicking a- * chip drops its prompt into the composer (instead of sending) and shows the- * chip's contextual starters, which append to the draft.+ * Fill-in-the-blank prompt templates, rendered as chips between the composer+ * and the starters. Clicking one drops its prompt stem into the composer+ * (instead of sending) and shows the template's completions, which append to+ * the draft.*/- prefillChips?: PrefillChip[];+ promptTemplates?: PromptTemplate[];/*** Children are not allowed when using props-based content*/@@ -68,7 +69,7 @@ interface WelcomeScreenWithChildrenProps extends WelcomeScreenBaseProps {image?: never;starters?: never;starterVariant?: never;- prefillChips?: never;+ promptTemplates?: never;}export type WelcomeScreenProps = WelcomeScreenWithContentProps | WelcomeScreenWithChildrenProps;@@ -88,8 +89,8 @@ export const WelcomeScreen = (props: WelcomeScreenProps) => {const ownVariant = "starterVariant" in props ? props.starterVariant : undefined;const starters = ownStarters ?? fromCtx.starters ?? [];const starterVariant = ownVariant ?? fromCtx.starterVariant ?? "long";- const prefillChips = ("prefillChips" in props ? props.prefillChips : undefined) ?? [];- const hasChips = prefillChips.length > 0;+ const promptTemplates = ("promptTemplates" in props ? props.promptTemplates : undefined) ?? [];+ const hasChips = promptTemplates.length > 0;const messages = useThread((s) => s.messages);const isLoadingMessages = useThread((s) => s.isLoadingMessages);@@ -98,7 +99,7 @@ export const WelcomeScreen = (props: WelcomeScreenProps) => {// Prefill-chips draft state — owned here (not in the composer) so chips can// write into the draft. Hooks stay unconditional; unused without chips.const [draft, setDraft] = useState("");- const [selectedChip, setSelectedChip] = useState<PrefillChip | null>(null);+ const [selectedChip, setSelectedChip] = useState<PromptTemplate | null>(null);const inputRef = useRef<HTMLTextAreaElement>(null);const selectedThreadId = useThreadList((s) => s.selectedThreadId);@@ -152,7 +153,7 @@ export const WelcomeScreen = (props: WelcomeScreenProps) => {}};- const handleChipClick = (chip: PrefillChip) => {+ const handleChipClick = (chip: PromptTemplate) => {if (isRunning) return;setDraft(chip.prompt);setSelectedChip(chip);@@ -221,7 +222,7 @@ export const WelcomeScreen = (props: WelcomeScreenProps) => {</div>{hasChips ? (<WelcomePrefillChips- chips={prefillChips}+ chips={promptTemplates}starters={starters}starterVariant={starterVariant}draft={draft}diff --git a/packages/react-ui/src/components/AgentInterface/__tests__/WelcomePrefillChips.ssr.test.tsx b/packages/react-ui/src/components/AgentInterface/__tests__/WelcomePrefillChips.ssr.test.tsxindex 6a4feed16..e20616548 100644--- a/packages/react-ui/src/components/AgentInterface/__tests__/WelcomePrefillChips.ssr.test.tsx+++ b/packages/react-ui/src/components/AgentInterface/__tests__/WelcomePrefillChips.ssr.test.tsx@@ -2,14 +2,14 @@ import { ChatProvider } from "@openuidev/react-headless";import { renderToString } from "react-dom/server";import { describe, expect, it } from "vitest";import { makeMockLLM } from "../../../__test-helpers/mockChat";-import type { PrefillChip } from "../../../types/PrefillChip";+import type { PromptTemplate } from "../../../types/PromptTemplate";import { WelcomePrefillChips } from "../components/WelcomePrefillChips";-const CHIPS: PrefillChip[] = [+const CHIPS: PromptTemplate[] = [{displayText: "Create a presentation",prompt: "Create a presentation about ",- starters: [{ displayText: "Our Q2 business review", prompt: "our Q2 business review" }],+ completions: [{ displayText: "Our Q2 business review", prompt: "our Q2 business review" }],},];const STARTERS = [{ displayText: "Quarterly deck", prompt: "Create a Q2 deck." }];diff --git a/packages/react-ui/src/components/AgentInterface/__tests__/WelcomeScreen.ssr.test.tsx b/packages/react-ui/src/components/AgentInterface/__tests__/WelcomeScreen.ssr.test.tsxindex 9bc0b8855..e57e85c8e 100644--- a/packages/react-ui/src/components/AgentInterface/__tests__/WelcomeScreen.ssr.test.tsx+++ b/packages/react-ui/src/components/AgentInterface/__tests__/WelcomeScreen.ssr.test.tsx@@ -2,10 +2,10 @@ import { ChatProvider } from "@openuidev/react-headless";import { renderToString } from "react-dom/server";import { describe, expect, it } from "vitest";import { makeMockLLM } from "../../../__test-helpers/mockChat";-import type { PrefillChip } from "../../../types/PrefillChip";+import type { PromptTemplate } from "../../../types/PromptTemplate";import { WelcomeScreen } from "../WelcomeScreen";-const CHIPS: PrefillChip[] = [+const CHIPS: PromptTemplate[] = [{displayText: "Create a presentation",prompt: "Create a presentation about ",@@ -20,7 +20,7 @@ const render = (ui: React.ReactElement) =>describe("WelcomeScreen SSR", () => {it("renders chips mode: chip row, layers wrapper, empty-draft container attribute", () => {const html = render(- <WelcomeScreen title="Good to see you" starters={STARTERS} prefillChips={CHIPS} />,+ <WelcomeScreen title="Good to see you" starters={STARTERS} promptTemplates={CHIPS} />,);expect(html).toContain("data-has-prefill-chips");expect(html).toContain("openui-agent-welcome-screen__starters-layers");@@ -41,7 +41,7 @@ describe("WelcomeScreen SSR", () => {});it("treats an empty chips array as absent", () => {- const html = render(<WelcomeScreen title="Hi" starters={STARTERS} prefillChips={[]} />);+ const html = render(<WelcomeScreen title="Hi" starters={STARTERS} promptTemplates={[]} />);expect(html).not.toContain("openui-agent-welcome-screen__starters-layers");expect(html).not.toContain("data-has-prefill-chips");});diff --git a/packages/react-ui/src/components/AgentInterface/components/WelcomePrefillChips.tsx b/packages/react-ui/src/components/AgentInterface/components/WelcomePrefillChips.tsxindex 99bdfc9c8..5ac2f4e91 100644--- a/packages/react-ui/src/components/AgentInterface/components/WelcomePrefillChips.tsx+++ b/packages/react-ui/src/components/AgentInterface/components/WelcomePrefillChips.tsx@@ -1,9 +1,9 @@import { ConversationStarterProps } from "../../../types/ConversationStarter";-import { PrefillChip } from "../../../types/PrefillChip";+import { PromptTemplate } from "../../../types/PromptTemplate";import { ConversationStarter, ConversationStarterVariant } from "../ConversationStarter";interface PrefillChipButtonProps {- chip: PrefillChip;+ chip: PromptTemplate;disabled: boolean;onClick: () => void;}@@ -20,12 +20,12 @@ const PrefillChipButton = ({ chip, disabled, onClick }: PrefillChipButtonProps));export interface WelcomePrefillChipsProps {- chips: PrefillChip[];+ chips: PromptTemplate[];starters: ConversationStarterProps[];starterVariant: ConversationStarterVariant;draft: string;- selectedChip: PrefillChip | null;- onChipClick: (chip: PrefillChip) => void;+ selectedChip: PromptTemplate | null;+ onChipClick: (chip: PromptTemplate) => void;onContextualSelect: (starter: ConversationStarterProps) => void;disabled: boolean;}@@ -70,7 +70,7 @@ export const WelcomePrefillChips = ({{selectedChip && (<div className="openui-agent-welcome-screen__starters-layer"><ConversationStarter- starters={selectedChip.starters}+ starters={selectedChip.completions}variant="long"onSelect={onContextualSelect}/>diff --git a/packages/react-ui/src/components/AgentInterface/stories/AgentInterface.stories.tsx b/packages/react-ui/src/components/AgentInterface/stories/AgentInterface.stories.tsxindex b983a7e8c..d9a27edff 100644--- a/packages/react-ui/src/components/AgentInterface/stories/AgentInterface.stories.tsx+++ b/packages/react-ui/src/components/AgentInterface/stories/AgentInterface.stories.tsx@@ -14,7 +14,7 @@ import {} from "lucide-react";import { useState } from "react";import { makeMockLLM, makeMockStorage, mockSSEResponse } from "../../../__test-helpers/mockChat";-import type { PrefillChip } from "../../../types/PrefillChip";+import type { PromptTemplate } from "../../../types/PromptTemplate";import { Button } from "../../Button";import { IconButton } from "../../IconButton";import { AgentInterface } from "../AgentInterface";@@ -116,12 +116,12 @@ const LONG_STARTERS = [},];-const PREFILL_CHIPS: PrefillChip[] = [+const PROMPT_TEMPLATES: PromptTemplate[] = [{displayText: "Create a presentation",prompt: "Create a presentation about ",icon: <PresentationIcon size={16} />,- starters: [+ completions: [{ displayText: "Our Q2 business review", prompt: "our Q2 business review", icon: <></> },{ displayText: "A product launch plan", prompt: "a product launch plan", icon: <></> },{@@ -135,7 +135,7 @@ const PREFILL_CHIPS: PrefillChip[] = [displayText: "Write a report",prompt: "Write a report on ",icon: <FileText size={16} />,- starters: [+ completions: [{ displayText: "The EV market in 2026", prompt: "the EV market in 2026", icon: <></> },{displayText: "Our quarterly performance",@@ -267,7 +267,7 @@ export const WelcomeWithPrefillChips = {<AgentInterface.Welcometitle="Good to see you"description="What's on your mind today?"- prefillChips={PREFILL_CHIPS}+ promptTemplates={PROMPT_TEMPLATES}glowAnimation/></AgentInterface>diff --git a/packages/react-ui/src/index.ts b/packages/react-ui/src/index.tsindex 5e2ffa9f8..555b81a70 100644--- a/packages/react-ui/src/index.ts+++ b/packages/react-ui/src/index.ts@@ -136,4 +136,4 @@ export type {ConversationStarterIcon,ConversationStarterProps,} from "./types/ConversationStarter";-export type { PrefillChip } from "./types/PrefillChip";+export type { PromptTemplate } from "./types/PromptTemplate";diff --git a/packages/react-ui/src/types/PrefillChip.ts b/packages/react-ui/src/types/PrefillChip.tsdeleted file mode 100644index 68435a33f..000000000--- a/packages/react-ui/src/types/PrefillChip.ts+++ /dev/null@@ -1,16 +0,0 @@-import { ReactNode } from "react";-import { ConversationStarterProps } from "./ConversationStarter";--/**- * A ChatGPT-style prefill chip for the welcome screen: clicking drops- * `prompt` into the welcome composer (instead of sending), then shows the- * chip's contextual `starters`, which append to the draft on click.- */-export interface PrefillChip {- displayText: string;- prompt: string;- /** Optional icon; omit for none (chips render no default icon). */- icon?: ReactNode;- /** Contextual starters shown after this chip prefills the composer. */- starters: ConversationStarterProps[];-}diff --git a/packages/react-ui/src/types/PromptTemplate.ts b/packages/react-ui/src/types/PromptTemplate.tsnew file mode 100644index 000000000..876ea6983--- /dev/null+++ b/packages/react-ui/src/types/PromptTemplate.ts@@ -0,0 +1,18 @@+import { ReactNode } from "react";+import { ConversationStarterProps } from "./ConversationStarter";++/**+ * A fill-in-the-blank prompt for the welcome screen, rendered as a chip:+ * clicking drops the incomplete `prompt` stem into the welcome composer+ * (instead of sending), then shows the template's `completions`, which append+ * to the draft on click.+ */+export interface PromptTemplate {+ displayText: string;+ /** The prompt stem dropped into the composer, e.g. "Create a deck about ". */+ prompt: string;+ /** Optional icon; omit for none (chips render no default icon). */+ icon?: ReactNode;+ /** Suggested completions shown once this template is in the composer. */+ completions: ConversationStarterProps[];+}