AI Code Run - React Component | Kokonut UI
AI Code Run
The assistant runs a short Python script in the reply. A marker steps down the lines, the output prints, and the chart it draws grows in.
Install with
npx shadcn@latest add https://kokonutui.com/r/ai-code-run.json
How did signups do over the last six weeks?
I’ll pull them from the export and plot it.
pysignups.py
Running
import pandas as pd
df = pd.read_csv("signups.csv")
weekly = df.groupby("week").size().tail(6)
growth = weekly.iloc[-1] / weekly.iloc[0] - 1
print(f"{weekly.sum():,} signups, {growth:+.0%}")
weekly.plot.bar()
›4,812 signups, +38%
952
| Oct 5 | Oct 12 | Oct 19 | Oct 26 | Nov 2 | Nov 9 |
|---|---|---|---|---|---|
| - | - | - | - | - | - |
Signups grew 38% over six weeks, to 952 last week. The one dip, the week of Nov 2, lines up with the pricing page being down for a day.
Ran in 1.9s. 4,812 signups, +38%
Usage
With no props it plays the demo. Pass status to drive it from your code tool: writing while the model streams the code in, running while it executes (with activeLine if your sandbox reports it), then done or error. stdout shows as soon as you pass it, and on error it reads as the error. The chart and answer show once it's done. The user's bubble and the line above the card only show when you pass prompt and message.
Here it’s fed the way a run streams: the code writes in, the lines run, then the result. Play with an error stops on line 4.
pyrevenue.py
Writing
import pandas as pd
df = pd.read_csv("orders.csv")
monthly = df.groupby("month").total.sum().tail(4)
print(f"{monthly.iloc[-1]:,.0f} in Oct")
monthly.plot.bar()
›52,300 in Oct
52300
| Jul | Aug | Sep | Oct |
|---|---|---|---|
| - | - | - | - |
October was your best month yet: $52.3k, up 16% on September.
Ran in 2.4s. 52,300 in Oct
Leave status out with your own code and it plays through a line every lineMs, like the demo. The root carries data-state with the status.
Installation
AI Code Run is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-code-run.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/ai-code-run
Or add it by hand: install its packages, then copy the source from above into components/kokonutui/ai-code-run.tsx.
npm install lucide-react motion
Props
prompt:string- The user's message, drawn as a bubble. Only the demo draws one by default.message:string- What the assistant says before the code.filename:string-code:string- The script. Whilewriting, pass it as it streams in.stdout:string- What the script prints, or the error when it fails.bars:CodeRunBar[]- The chart the script draws, shown once it's done.answer:ReactNode- The reply under the run, shown once it's done.status:CodeRunStatus- Pass it to drive the card from your run; leave it out and the code plays through line by line onlineMs.activeLine:number- The line running now, from 1, whilerunning.duration:number- How long the run took, in seconds, shown once it’s done.onRunAgain:() => void- Shows Run again once the run is over. The demo replays by itself.lineMs:number- Default320- Demo only: how long each line takes, in ms.className:string- Extra classes for the root element.
CodeRunBar
label: requiredstringvalue: requirednumber
CodeRunStatus
Where the run is: the model writing the code, the code running, then done or error. Matches a code tool's part going from input-streaming to input-available to output-available or output-error.
type CodeRunStatus = "writing" | "running" | "done" | "error";
Dependencies
| Needs | Version | Comes from |
|---|---|---|
lucide-react |
^0.556.0 |
npm, installed by the CLI |
motion |
^12.23.25 |
npm, installed by the CLI |
cn from lib/utils.ts |
shadcn init | |
| React | 19 |
Your app |
| Tailwind CSS | 4 |
Your app |
| No provider, font or global CSS to set up: the file works as soon as it lands. |