Inline AI

Ask AI to rewrite, shorten or explain a selection, in place.

Due to the fact that the migration is taking longer than we originally anticipated, the release of the new billing page will be pushed out to next week.

AI
Edit
Tone
Uses 1 credit

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/inline-ai

Usage

import { InlineAi, type InlineAiStatus } from "./ui/uicontext/components/kit/InlineAi.ts"
const Message = UiSchema.TaggedEnum({	RequestedRewrite: { prompt: Schema.String },	KeptRewrite: { option: Schema.String },	DiscardedRewrite: {},	StoppedRewrite: {},})// your app runs the model and owns the document: pass the run's status and text, and write the// answer into the document only on Keepexport const RewriteSelection = (	h: Html.H<typeof Message.Type>,	selection: string,	run: { readonly status: InlineAiStatus; readonly result: string },) =>	InlineAi(h, {		props: { id: "rewrite", original: selection, ...run },		onEmit: {			RequestedGenerate: ({ prompt }) => Message.RequestedRewrite({ prompt }),			RequestedRetry: ({ prompt }) => Message.RequestedRewrite({ prompt }),			RequestedKeep: ({ option }) => Message.KeptRewrite({ option }),			RequestedDiscard: () => Message.DiscardedRewrite(),			RequestedStop: () => Message.StoppedRewrite(),		},	})

Examples

AI cells

A column AI fills in: generate, generating with Stop, generated, out of date, failed with retry, refused, and edited by a person, which runs skip.

CompanyIndustry ✦
Northwind Freight
✦Logistics, freight forwarding
Halcyon Health
Bluebird Bakery
Food and drinkInputs changed
Cobalt Labs
The website didn't load
Fjord Outfitters
Out of AI credits this month
Elm Studio
Design agency (set by Mira)Edited, runs skip it

Failed and refused

A run that failed says what happened, with Try again. One the workspace doesn't allow says why, and offers no run.

AI
Uses 1 credit
AI

API reference

Props

InlineAi props
NameTypeDefaultDescription
agentIdstring—The id agents see this by; inline-ai:<id> when left out
idrequiredstring—Identifies the run in the events it sends
variant"block" | "cell""block"A prompt and answer under a selection, or a table cell that generates its value; "block" by default
statusrequiredInlineAiStatus—Where the run stands: idle, waiting, streaming, proposed, succeeded, kept, discarded, failed or refused
resultrequiredstring—The answer so far, as Markdown
originalstring—The text being rewritten: the answer shows as a diff against it
promptstring—The prompt this answer came from
presetsInlineAiPreset[]—Quick actions offered before anything is typed: "Improve writing", "Make shorter"
keepOptionsKeepOption[]—How to keep it; the first is the main one (default: "Keep")
placeholderstring—Hint text in the empty prompt; "Ask AI to edit or write…" when left out
noticestring—For failed and refused: what went wrong and what to do, as a sentence
usagestring—What a run costs, said before it runs: "Uses 1 credit"
generatedAtstring—When it was generated, as an ISO timestamp: "Generated Nov 29, 10:00 AM"
localestring—Formats generatedAt; the reader's own when left out
timeZonestring—The time zone for generatedAt; the reader's own when left out
attributionAttributionData—Who made it, for whom, and how
canCan(["run"])—What the viewer may do; without "run" it shows the answer but can't run, keep or retry (a viewer, a read-only cell). Everything when left out.
labelstring—The cell's field, for its accessible name

Events

InlineAi events
EventPayloadDescription
RequestedGenerate{ id: string; prompt: string; preset: string | null }A new run; on a proposal, the prompt refines it
RequestedKeep{ id: string; option: string }The person kept the answer, with one of keepOptions
RequestedRetry{ id: string; prompt: string }A new run with the same prompt
RequestedDiscard{ id: string }The person discarded the answer
RequestedStop{ id: string }The person stopped the run

Accessibility

  • The prompt is a labelled field with a Send button, and the quick actions are a named group of buttons.
  • The answer is announced as it's written. Escape stops it while it runs, and discards the proposal after.
  • Keeping text in the document is consequential, so an agent must name what it keeps.

Source