Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- 5.6 kB JS 4.9 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 11 tests
326 characters
Unknown: {{agent.nmae}} isn't a variable the app fills in, so it would be sent as written.
Variables
- Used 1 time
The customer's first name
- Used 1 time
Their plan: Free, Team or Business
- Used 1 time
The ticket's subject line
- Used 1 time
What they wrote, as plain text
- Not used
The person the reply is signed by
- Not used
Today's date in the customer's language
- UnknownUsed 1 time
Preview
You draft replies for the support team. Be brief and warm, and never promise dates.
The customer is Ada, on the Team plan.
Subject: Can't export invoices to CSV
They wrote:
Every export since Monday comes back empty. We close the month on Friday.
Answer what they asked, in their language. If it's a bug, say we've passed it to the team.
Sign off as {{agent.nmae}}.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { PromptTemplate, type TemplateVariable } from "./ui/uicontext/components/PromptTemplate.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 44rem)" } })const variables: ReadonlyArray<TemplateVariable> = [ { name: "customer.name", description: "The customer's first name", sample: "Ada" }, { name: "customer.plan", description: "Their plan: Free, Team or Business", sample: "Team" }, { name: "ticket.subject", description: "The ticket's subject line", sample: "Can't export invoices to CSV" }, { name: "ticket.body", description: "What they wrote, as plain text", sample: "Every export since Monday comes back empty. We close the month on Friday." }, { name: "agent.name", description: "The person the reply is signed by", sample: "Tomás" }, { name: "today", description: "Today's date in the customer's language" },]// a support team's reply drafter: one variable is misspelled, so it's flagged before it shipsconst value = `You draft replies for the support team. Be brief and warm, and never promise dates.The customer is {{customer.name}}, on the {{customer.plan}} plan.Subject: {{ticket.subject}}They wrote:{{ticket.body}}Answer what they asked, in their language. If it's a bug, say we've passed it to the team.Sign off as {{agent.nmae}}.`export const ReplyInstructions = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( PromptTemplate(h, { key: "reply", props: { label: "Reply instructions", value, variables, rows: 8 } }), )} and the warning clears. The Insert buttons put a variable where the cursor is." }When to use
Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples. Use Composer instead when the text is a message to send now, with no {{variables}} for the app to fill in.
Usage
import { PromptTemplate } from "./ui/uicontext/components/PromptTemplate.ts"export const Instructions = <M>(h: Html.H<M>, prompt: string, onChange: (text: string) => M) => PromptTemplate(h, { props: { label: "Instructions", value: prompt, variables: [{ name: "customer.name", description: "The customer's first name", sample: "Ada" }], }, onEmit: { RequestedChange: ({ value }) => onChange(value) }, })Examples
Variables the writer makes up
Without variables, any name goes: each is listed so it can be tried with a sample.
118 characters
Variables
- Used 1 time
- Used 1 time
- Used 1 time
Preview
Summarize {{doc}} for {{audience}} in {{length}} bullet points. Keep the numbers exact and say what's still undecided.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { PromptTemplate } from "./ui/uicontext/components/PromptTemplate.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 44rem)" } })// a team's own saved prompt: no list from the app, so every name it uses is listed with a sample fieldconst value = "Summarize {{doc}} for {{audience}} in {{length}} bullet points. Keep the numbers exact and say what's still undecided."export const SavedPrompt = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( PromptTemplate(h, { key: "saved", props: { id: "saved", label: "Saved prompt", value, rows: 3, placeholder: "Write a prompt. Put {{name}} where a value goes." } }), )API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | The editor's name: "Instructions". |
valuerequired | string | — | The template to start with. |
variables | TemplateVariable[] | — | The variables the app fills in. Without it, any name goes and nothing is flagged. |
rows | number | 6 | The editor's height in lines before it grows; 6 by default. |
id | string | "prompt" | Starts the ids inside it, unique on the page; "prompt" by default. |
placeholder | string | — | — |
locale | string | — | For the counts; the browser's by default. |
Events
| Event | Payload | Description |
|---|---|---|
RequestedChange | { value: string; unknown: string[] } | The text changed: the template, and the variables in it the app doesn't offer. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/prompt-template