AI Mention
Pointing an agent at context: an @ menu for files and agents, removable context chips, and inline mentions inside a sentence.
"use client"
import * as React from "react"
import { AtSign, BookOpen, FileCode, Plus, X } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Face,
Roll,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
const CSS = `
.aik-mn-box{position:relative;display:grid;width:min(100%,400px)}
.aik-mn-menu{position:absolute;left:0;right:0;bottom:calc(100% + 8px);z-index:2;padding:5px;border-radius:16px;background:var(--aik-card);box-shadow:var(--aik-sh-pop);transform-origin:50% 100%}
.aik-mn-hl{position:absolute;left:5px;right:5px;top:0;height:36px;border-radius:11px;background:var(--aik-raised);transform:translateY(var(--y,0px));transition:transform var(--aik-d-state) var(--aik-ease-move)}
.aik-mn-group{position:relative;display:flex;align-items:center;height:28px;padding:0 10px}
.aik-mn-opt{position:relative;display:flex;align-items:center;gap:10px;width:100%;height:36px;padding:0 10px;border-radius:11px;text-align:left;font-size:13.5px;color:var(--aik-text)}
.aik-mn-opt > svg{color:var(--aik-text-3)}
.aik-mn-opt b{font-weight:500;white-space:nowrap}
.aik-mn-opt > span:not(.aik-face){flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--aik-text-3);font-size:12.5px}
.aik-mn-opt .aik-kbd{opacity:0;transition:opacity var(--aik-d-state)}
.aik-mn-opt[aria-selected="true"] .aik-kbd{opacity:1}
.aik-mn-none{position:relative;display:flex;align-items:center;height:36px;padding:0 10px;color:var(--aik-text-3);font-size:13px}
.aik-mn-line{display:flex;align-items:center;gap:10px;height:52px;padding:0 12px 0 14px;border-radius:17px;background:var(--aik-card);box-shadow:var(--aik-sh-pop);min-width:0}
.aik-mn-line > svg{color:var(--aik-text-3);transition:color var(--aik-d-state)}
.aik-mn-box[data-open] .aik-mn-line > svg{color:var(--aik-blue)}
.aik-mn-input{flex:1;min-width:0;height:100%;border:0;outline:0;background:none;font-size:14.5px}
.aik-mn-input::placeholder{color:var(--aik-text-3);opacity:1}
.aik-mn-chips{display:grid;gap:10px;width:min(100%,400px);padding:12px;border-radius:16px;background:var(--aik-card);box-shadow:var(--aik-sh-card)}
.aik-mn-row{display:flex;flex-wrap:wrap;gap:6px}
.aik-mn-chip{display:inline-flex;align-items:center;gap:6px;height:32px;max-width:100%;padding:0 4px 0 9px;border-radius:10px;box-shadow:inset 0 0 0 1px var(--aik-line-2);font-size:13px;animation:aik-pop var(--aik-d-enter) var(--aik-ease-out) both}
.aik-mn-chip[data-kind="agent"]{padding-left:7px}
.aik-mn-chip[data-leaving]{animation:aik-mn-leave var(--aik-d-exit) var(--aik-ease-in) both}
@keyframes aik-mn-leave{to{opacity:0;transform:scale(.92)}}
.aik-mn-chip > svg{color:var(--aik-text-3)}
.aik-mn-chip b{min-width:0;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-mn-chip i{font:11.5px var(--aik-mono);font-style:normal;color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-mn-x{display:grid;place-items:center;flex:none;width:24px;height:24px;border-radius:7px;color:var(--aik-text-3);transition:background var(--aik-d-state),color var(--aik-d-state),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-mn-x:hover{background:var(--aik-hover);color:var(--aik-text)}
.aik-mn-x:active{transform:scale(.9)}
.aik-mn-add{display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 10px 0 8px;border-radius:10px;border:1px dashed var(--aik-line-3);color:var(--aik-text-2);font-size:13px;transition:color var(--aik-d-state),border-color var(--aik-d-state),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-mn-add:hover{color:var(--aik-text);border-color:var(--aik-text-3)}
.aik-mn-add:active{transform:scale(.96)}
.aik-mn-sum{display:grid;gap:7px}
.aik-mn-sum > div{display:flex;justify-content:space-between;align-items:center;gap:12px;font-size:12px;line-height:16px;color:var(--aik-text-3)}
.aik-mn-sum .aik-roll{font-family:var(--aik-mono);font-size:11.5px;font-variant-numeric:tabular-nums}
.aik-mn-bar{display:block;height:4px;border-radius:2px;background:var(--aik-line-2);overflow:hidden}
.aik-mn-bar i{display:block;height:100%;border-radius:2px;background:var(--aik-text-2);transform-origin:0 50%;transform:scaleX(var(--p,0));transition:transform var(--aik-d-panel) var(--aik-ease-out),background var(--aik-d-state)}
.aik-mn-bar[data-near] i{background:var(--aik-amber-fill)}
.aik-mn-text{display:grid;gap:12px;width:min(100%,400px)}
.aik-mn-para{font-size:15px;line-height:30px;color:var(--aik-text-2)}
.aik-mn-tok{display:inline-flex;align-items:center;gap:5px;height:24px;margin:0 1px;padding:0 8px 0 6px;border-radius:8px;vertical-align:middle;font-size:13.5px;line-height:1;font-weight:500;color:var(--aik-blue);background:color-mix(in oklab,var(--aik-blue) 12%,transparent);box-shadow:0 0 0 1.5px transparent;transition:box-shadow var(--aik-d-state) var(--aik-ease-out)}
.aik-mn-tok[data-kind="agent"]{padding-left:4px;color:var(--aik-text);background:var(--aik-raised)}
.aik-mn-tok[data-on]{box-shadow:0 0 0 1.5px color-mix(in oklab,currentColor 55%,transparent)}
.aik-mn-slot{display:grid;align-items:start;min-height:56px}
.aik-mn-card{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:14px;background:var(--aik-card);box-shadow:var(--aik-sh-pop);min-width:0}
.aik-mn-tile{display:grid;place-items:center;flex:none;width:32px;height:32px;border-radius:9px;background:var(--aik-raised);color:var(--aik-text-2)}
.aik-mn-card > div{display:grid;flex:1;min-width:0}
.aik-mn-card b{font-weight:600;font-size:13.5px;line-height:18px}
.aik-mn-card > div span{font-size:12px;line-height:17px;color:var(--aik-text-3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-mn-card[data-kind="file"] > div span{font-family:var(--aik-mono)}
.aik-mn-card em{flex:none;font:11.5px var(--aik-mono);font-style:normal;color:var(--aik-text-3)}
.aik-mn-hint{align-self:center;font-size:12.5px;line-height:18px;color:var(--aik-text-3)}
`
export interface AiMentionItem {
id: string
kind: "file" | "agent" | "doc"
/** What is shown and inserted, without the @. */
name: string
/** A path for files, a role for agents, a section for docs. */
detail?: string
/** How many tokens this item adds to the context. */
tokens?: number
/** Face colour, for agents. */
tone?: AiTone | (string & {})
/** Face shape, for agents. */
shape?: AiShape
}
const GROUPS = [
["file", "Files"],
["agent", "Agents"],
["doc", "Docs"],
] as const
const QUERY = /(^|\s)@([\w./-]*)$/
const PAD = 5
const LABEL = 28
const ROW = 36
/** 2140 becomes "2.1k". */
export function formatTokens(tokens: number) {
return tokens >= 1000 ? `${(tokens / 1000).toFixed(1)}k` : String(tokens)
}
function KindIcon({ item, size = 16 }: { item: AiMentionItem; size?: number }) {
if (item.kind === "agent")
return (
<Face
size={size + 2}
tone={item.tone ?? "blue"}
shape={item.shape ?? "orb"}
/>
)
if (item.kind === "doc") return <BookOpen size={size} />
return <FileCode size={size} />
}
export interface AiMentionInputProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onSubmit"
> {
/** Everything that can be mentioned. */
items: AiMentionItem[]
value: string
onValueChange: (value: string) => void
/** Called when an item is inserted from the menu. */
onMention?: (item: AiMentionItem) => void
/** Called with the trimmed text on Enter while the menu is closed. */
onSubmit?: (value: string) => void
/** Highlighted menu row. Leave undefined to let the arrow keys manage it. */
highlight?: number
placeholder?: string
}
/** A prompt field where @ opens a grouped menu of files, agents and docs that filters as you type. */
export function AiMentionInput({
items,
value,
onValueChange,
onMention,
onSubmit,
highlight,
placeholder = "Ask, or type @ to add context",
className,
...rest
}: AiMentionInputProps) {
const listId = React.useId()
const [ownRow, setOwnRow] = React.useState(0)
const [dismissed, setDismissed] = React.useState<string | null>(null)
const found = value.match(QUERY)
const query = found ? (found[2] ?? "").toLowerCase() : null
const open = query !== null && dismissed !== value
const shown = open
? items.filter((item) => item.name.toLowerCase().includes(query ?? ""))
: []
const ordered = GROUPS.flatMap(([kind]) =>
shown.filter((item) => item.kind === kind)
)
const row = Math.min(highlight ?? ownRow, Math.max(ordered.length - 1, 0))
let offset = PAD
let index = 0
let highlightY = PAD
const groups = GROUPS.map(([kind, title]) => {
const members = ordered.filter((item) => item.kind === kind)
if (members.length === 0) return null
offset += LABEL
const rows = members.map((item) => {
const entry = { item, index }
if (index === row) highlightY = offset
index += 1
offset += ROW
return entry
})
return { kind, title, rows }
})
const insert = (item: AiMentionItem) => {
onValueChange(
value.replace(QUERY, (_all, lead: string) => `${lead}@${item.name} `)
)
onMention?.(item)
setOwnRow(0)
}
const current = ordered[row]
return (
<div
{...rest}
className={cx("aik aik-mn-box", className)}
data-open={open ? "" : undefined}
>
<AiKitStyles />
<AiStyle id="ai-mention" css={CSS} />
{open ? (
<div
id={listId}
className="aik-mn-menu aik-pop"
role="listbox"
aria-label="Add context"
>
{ordered.length > 0 ? (
<div
className="aik-mn-hl"
style={{ "--y": `${highlightY}px` } as React.CSSProperties}
/>
) : (
<div className="aik-mn-none">Nothing matches @{query}</div>
)}
{groups.map((group) =>
group ? (
<div key={group.kind} role="group" aria-label={group.title}>
<div className="aik-mn-group">
<span className="aik-label">{group.title}</span>
</div>
{group.rows.map(({ item, index: at }) => (
<button
key={item.id}
id={`${listId}-${item.id}`}
type="button"
role="option"
aria-selected={at === row}
className="aik-mn-opt"
tabIndex={-1}
onMouseEnter={() => setOwnRow(at)}
onMouseDown={(event) => event.preventDefault()}
onClick={() => insert(item)}
>
<KindIcon item={item} />
<b>{item.name}</b>
<span>{item.detail}</span>
<kbd className="aik-kbd">⏎</kbd>
</button>
))}
</div>
) : null
)}
</div>
) : null}
<div className="aik-mn-line">
<AtSign size={16} />
<input
className="aik-mn-input"
role="combobox"
aria-expanded={open}
aria-controls={listId}
aria-autocomplete="list"
aria-activedescendant={
open && current ? `${listId}-${current.id}` : undefined
}
aria-label={placeholder}
placeholder={placeholder}
value={value}
onChange={(event) => {
setOwnRow(0)
onValueChange(event.target.value)
}}
onKeyDown={(event) => {
if (open && ordered.length > 0 && event.key === "ArrowDown") {
event.preventDefault()
setOwnRow((row + 1) % ordered.length)
} else if (open && ordered.length > 0 && event.key === "ArrowUp") {
event.preventDefault()
setOwnRow((row - 1 + ordered.length) % ordered.length)
} else if (event.key === "Enter") {
event.preventDefault()
if (open && current) insert(current)
else if (value.trim()) onSubmit?.(value.trim())
} else if (event.key === "Escape" && open) {
event.preventDefault()
setDismissed(value)
}
}}
/>
<kbd className="aik-kbd">@</kbd>
</div>
</div>
)
}
export interface AiContextChipsProps extends React.HTMLAttributes<HTMLDivElement> {
/** What the agent has been given. */
items: AiMentionItem[]
/** Called once a chip has finished leaving. */
onRemove?: (id: string) => void
/** Shows the add button when set. */
onAdd?: () => void
/** Ids to play the leave animation on, when you remove items yourself. */
removing?: string[]
/** Token budget. Adds a bar that turns amber past 80 percent. */
budget?: number
}
/** The context as removable chips, each with its kind, name and token count, and a running total. */
export function AiContextChips({
items,
onRemove,
onAdd,
removing = [],
budget,
className,
...rest
}: AiContextChipsProps) {
const [leaving, setLeaving] = React.useState<string[]>([])
const timers = React.useRef<number[]>([])
React.useEffect(() => {
const pending = timers.current
return () => pending.forEach((timer) => window.clearTimeout(timer))
}, [])
const remove = (id: string) => {
if (leaving.includes(id)) return
setLeaving((list) => [...list, id])
timers.current.push(
window.setTimeout(() => {
setLeaving((list) => list.filter((item) => item !== id))
onRemove?.(id)
}, 160)
)
}
const gone = (id: string) => leaving.includes(id) || removing.includes(id)
const kept = items.filter((item) => !gone(item.id))
const total = kept.reduce((sum, item) => sum + (item.tokens ?? 0), 0)
const share = budget ? Math.min(total / budget, 1) : 0
return (
<div {...rest} className={cx("aik aik-mn-chips", className)}>
<AiKitStyles />
<AiStyle id="ai-mention" css={CSS} />
<div className="aik-mn-row" role="list" aria-label="Context">
{items.map((item) => (
<span
key={item.id}
role="listitem"
className="aik-mn-chip"
data-kind={item.kind}
data-leaving={gone(item.id) ? "" : undefined}
>
<KindIcon item={item} size={14} />
<b>{item.name}</b>
{item.tokens === undefined ? null : (
<i>{formatTokens(item.tokens)}</i>
)}
<button
type="button"
className="aik-mn-x"
aria-label={`Remove ${item.name}`}
onClick={() => remove(item.id)}
>
<X size={13} />
</button>
</span>
))}
{onAdd ? (
<button type="button" className="aik-mn-add" onClick={onAdd}>
<Plus size={14} />
Add context
</button>
) : null}
</div>
<div className="aik-mn-sum">
<div>
<span>
{kept.length} {kept.length === 1 ? "item" : "items"} in context
</span>
<Roll>
{budget
? `${formatTokens(total)} of ${formatTokens(budget)}`
: `${formatTokens(total)} tokens`}
</Roll>
</div>
{budget ? (
<span className="aik-mn-bar" data-near={share > 0.8 ? "" : undefined}>
<i style={{ "--p": share } as React.CSSProperties} />
</span>
) : null}
</div>
</div>
)
}
/** A run of text, or a mention inside it. */
export type AiMentionPart = string | AiMentionItem
export interface AiMentionTextProps extends React.HTMLAttributes<HTMLDivElement> {
/** The sentence, as strings and mention items in order. */
parts: AiMentionPart[]
/** The mention whose card is showing. Leave undefined to follow hover and focus. */
active?: string | null
onActiveChange?: (id: string | null) => void
/** Shown in the card's place while no mention is active. */
hint?: string
}
/** Mentions as pills inside a sentence. Hover or focus one to see what it points at. */
export function AiMentionText({
parts,
active,
onActiveChange,
hint = "Hover or focus a mention to see what it points at.",
className,
...rest
}: AiMentionTextProps) {
const cardId = React.useId()
const [own, setOwn] = React.useState<string | null>(null)
const currentId = active === undefined ? own : active
const current = parts.find(
(part): part is AiMentionItem =>
typeof part !== "string" && part.id === currentId
)
const show = (id: string | null) => {
setOwn(id)
onActiveChange?.(id)
}
return (
<div {...rest} className={cx("aik aik-mn-text", className)}>
<AiKitStyles />
<AiStyle id="ai-mention" css={CSS} />
<p className="aik-mn-para">
{parts.map((part, at) =>
typeof part === "string" ? (
<React.Fragment key={at}>{part}</React.Fragment>
) : (
<button
key={part.id}
type="button"
className="aik-mn-tok"
data-kind={part.kind}
data-on={part.id === currentId ? "" : undefined}
aria-describedby={part.id === currentId ? cardId : undefined}
onMouseEnter={() => show(part.id)}
onMouseLeave={() => show(null)}
onFocus={() => show(part.id)}
onBlur={() => show(null)}
>
<KindIcon item={part} size={14} />
{part.name}
</button>
)
)}
</p>
<div className="aik-mn-slot" aria-live="polite">
{current ? (
<div
key={current.id}
id={cardId}
role="tooltip"
className="aik-mn-card aik-pop"
data-kind={current.kind}
>
{current.kind === "agent" ? (
<Face
size={32}
tone={current.tone ?? "blue"}
shape={current.shape ?? "orb"}
mood="listen"
/>
) : (
<span className="aik-mn-tile">
<KindIcon item={current} />
</span>
)}
<div>
<b>{current.name}</b>
<span>{current.detail}</span>
</div>
{current.tokens === undefined ? null : (
<em>{formatTokens(current.tokens)} tokens</em>
)}
</div>
) : (
<span className="aik-mn-hint">{hint}</span>
)}
</div>
</div>
)
}
Installation
One command adds ai-mention and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/ai-mention.json
ai-mention-demo
"use client"
import * as React from "react"
import { AiDemo } from "@/lib/ai-demo"
import { typeInto, useAiLoop } from "@/lib/ai-kit"
import {
AiContextChips,
AiMentionInput,
AiMentionText,
type AiMentionItem,
type AiMentionPart,
} from "@/registry/tween/ai-mention"
const HERO: AiMentionItem = {
id: "hero",
kind: "file",
name: "hero.tsx",
detail: "registry/tween/hero.tsx",
tokens: 2140,
}
const MIRA: AiMentionItem = {
id: "mira",
kind: "agent",
name: "Mira",
detail: "Builds pages and sections",
tone: "blue",
shape: "orb",
}
const MOTION: AiMentionItem = {
id: "motion",
kind: "doc",
name: "Motion principles",
detail: "Guides · eases and timing",
tokens: 1820,
}
const ITEMS: AiMentionItem[] = [
HERO,
{
id: "pricing",
kind: "file",
name: "pricing-section.tsx",
detail: "components/pricing-section.tsx",
tokens: 3360,
},
{
id: "globals",
kind: "file",
name: "globals.css",
detail: "styles/globals.css",
tokens: 5210,
},
MIRA,
{
id: "odo",
kind: "agent",
name: "Odo",
detail: "Writes and runs the tests",
tone: "violet",
shape: "blob",
},
MOTION,
{
id: "registry",
kind: "doc",
name: "Registry guide",
detail: "Docs · adding a component",
tokens: 960,
},
]
function Menu() {
const root = React.useRef<HTMLDivElement>(null)
const [value, setValue] = React.useState("Tighten the copy in @")
const [row, setRow] = React.useState<number | undefined>(0)
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
setValue("")
setRow(0)
await sleep(700)
await typeInto(setValue, "Tighten the copy in @", sleep)
await sleep(700)
setRow(1)
await sleep(420)
setRow(2)
await sleep(420)
setRow(0)
await typeInto(
(text) => setValue(`Tighten the copy in @${text}`),
"he",
sleep,
140
)
await sleep(700)
setValue("Tighten the copy in @hero.tsx ")
await sleep(500)
await typeInto(
(text) => setValue(`Tighten the copy in @hero.tsx ${text}`),
"with @",
sleep
)
await sleep(500)
setRow(3)
await sleep(900)
setValue("Tighten the copy in @hero.tsx with @Mira ")
await sleep(1900)
},
{ gap: 400, enabled: !hands }
)
return (
<div
ref={root}
style={{
display: "grid",
alignContent: "end",
width: "min(100%, 400px)",
minHeight: 380,
}}
onPointerDown={() => {
setHands(true)
setRow(undefined)
}}
onKeyDown={() => {
setHands(true)
setRow(undefined)
}}
>
<AiMentionInput
items={ITEMS}
value={value}
onValueChange={setValue}
highlight={row}
onSubmit={() => setValue("")}
/>
</div>
)
}
const POOL = ITEMS.filter((item) => item.kind !== "agent")
function Chips() {
const root = React.useRef<HTMLDivElement>(null)
const [items, setItems] = React.useState<AiMentionItem[]>(POOL.slice(0, 3))
const [removing, setRemoving] = React.useState<string[]>([])
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
setRemoving([])
setItems(POOL.slice(0, 2))
await sleep(1100)
setItems(POOL.slice(0, 3))
await sleep(1000)
setItems(POOL.slice(0, 4))
await sleep(1500)
setRemoving(["globals"])
await sleep(180)
setItems((list) => list.filter((item) => item.id !== "globals"))
setRemoving([])
await sleep(1700)
},
{ gap: 500, enabled: !hands }
)
const next = POOL.find((item) => !items.some((had) => had.id === item.id))
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerDown={() => setHands(true)}
onKeyDown={() => setHands(true)}
>
<AiContextChips
items={items}
removing={removing}
budget={16000}
onRemove={(id) =>
setItems((list) => list.filter((item) => item.id !== id))
}
onAdd={next ? () => setItems((list) => [...list, next]) : undefined}
/>
</div>
)
}
const PARTS: AiMentionPart[] = [
"I rewrote the headline in ",
HERO,
" to match the pacing in ",
MOTION,
", then handed the tests to ",
{
...MIRA,
id: "odo",
name: "Odo",
detail: "Writes and runs the tests",
tone: "violet",
shape: "blob",
},
".",
]
const TOUR = ["hero", "motion", "odo", null] as const
function Inline() {
const root = React.useRef<HTMLDivElement>(null)
const [active, setActive] = React.useState<string | null>("hero")
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
for (const id of TOUR) {
setActive(id)
await sleep(id ? 1700 : 700)
}
},
{ gap: 200, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerEnter={() => setHands(true)}
onFocus={() => setHands(true)}
>
<AiMentionText parts={PARTS} active={hands ? undefined : active} />
</div>
)
}
export function AiMentionDemo({ only }: { only?: string }) {
return (
<AiDemo
only={only}
tabs={[
{ name: "@ menu", node: <Menu /> },
{ name: "Context chips", node: <Chips /> },
{ name: "Inline mentions", node: <Inline /> },
]}
/>
)
}
Installation
Usage
import {
AiContextChips,
AiMentionInput,
AiMentionText,
} from "@/components/ui/ai-mention"const items = [
{ id: "hero", kind: "file", name: "hero.tsx", detail: "registry/tween/hero.tsx", tokens: 2140 },
{ id: "mira", kind: "agent", name: "Mira", detail: "Builds pages", tone: "blue" },
{ id: "motion", kind: "doc", name: "Motion principles", detail: "Guides", tokens: 1820 },
]
const [value, setValue] = useState("")
<AiMentionInput
items={items}
value={value}
onValueChange={setValue}
onMention={(item) => attach(item)}
onSubmit={send}
/>Versions
AiMentionInputis a prompt field. Typing@opens a menu grouped into files, agents and docs that filters as you type. Arrow keys move a sliding highlight, Enter inserts the name, Escape closes.AiContextChipsshows what the agent already has as removable chips with a token count each and a running total. Passbudgetfor a bar that turns amber past 80 percent.AiMentionTextrenders mentions as pills inside a sentence. Hovering or focusing one shows a card with its path or role.
Props
AiMentionInput
| Prop | Type | Default | Description |
|---|---|---|---|
items | AiMentionItem[] | Everything that can be mentioned. | |
value | string | The field's text. | |
onValueChange | (value: string) => void | Called on every edit and when a mention is inserted. | |
onMention | (item: AiMentionItem) => void | Called when an item is picked from the menu. | |
onSubmit | (value: string) => void | Called on Enter while the menu is closed. | |
highlight | number | Controls the highlighted row. Omit to use the arrow keys. |
AiContextChips
| Prop | Type | Default | Description |
|---|---|---|---|
items | AiMentionItem[] | The chips. | |
onRemove | (id: string) => void | Called once a chip has finished leaving. | |
onAdd | () => void | Shows the add button when set. | |
removing | string[] | [] | Ids to animate out when you remove items yourself. |
budget | number | Token budget for the bar. |
AiMentionText
| Prop | Type | Default | Description |
|---|---|---|---|
parts | (string | AiMentionItem)[] | The sentence, as strings and mentions in order. | |
active | string | null | Controls which card shows. Omit to follow hover and focus. | |
onActiveChange | (id: string | null) => void | Called as the active mention changes. | |
hint | string | Shown while no mention is active. |
An AiMentionItem is { id, kind, name, detail?, tokens?, tone?, shape? }, where kind is "file", "agent" or "doc".