Skip to content

Commit 3856fbc

Browse files
committed
Use streamdown to show the thinking as it happens
1 parent 1f2bed4 commit 3856fbc

File tree

4 files changed

+121
-8
lines changed

4 files changed

+121
-8
lines changed

apps/webapp/app/components/code/AIQueryInput.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { AnimatePresence, motion } from "framer-motion";
2-
import { useCallback, useEffect, useRef, useState } from "react";
2+
import { Suspense, lazy, useCallback, useEffect, useRef, useState } from "react";
33
import { AISparkleIcon } from "~/assets/icons/AISparkleIcon";
4+
5+
// Lazy load streamdown to avoid SSR issues
6+
const Streamdown = lazy(() => import("streamdown").then((mod) => ({ default: mod.Streamdown })));
47
import { Button } from "~/components/primitives/Buttons";
58
import { Spinner } from "~/components/primitives/Spinner";
69
import { useEnvironment } from "~/hooks/useEnvironment";
@@ -316,10 +319,10 @@ export function AIQueryInput({ onQueryGenerated, autoSubmitPrompt }: AIQueryInpu
316319
</Button>
317320
)}
318321
</div>
319-
<div className="max-h-48 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600">
320-
<p className="whitespace-pre-wrap text-xs text-text-dimmed">
321-
{thinking.slice(-800)}
322-
</p>
322+
<div className="streamdown-container max-h-48 overflow-y-auto text-xs text-text-dimmed scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600">
323+
<Suspense fallback={<p className="whitespace-pre-wrap">{thinking}</p>}>
324+
<Streamdown isAnimating={isLoading}>{thinking}</Streamdown>
325+
</Suspense>
323326
</div>
324327
</div>
325328
</motion.div>

apps/webapp/app/tailwind.css

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,67 @@
106106
--gradient-angle: 360deg;
107107
}
108108
}
109+
110+
/* Streamdown markdown styling */
111+
.streamdown-container {
112+
& p {
113+
@apply my-1;
114+
}
115+
& h1, & h2, & h3, & h4, & h5, & h6 {
116+
@apply font-semibold text-text-bright mt-2 mb-1;
117+
}
118+
& h1 {
119+
@apply text-base;
120+
}
121+
& h2 {
122+
@apply text-sm;
123+
}
124+
& h3, & h4, & h5, & h6 {
125+
@apply text-xs;
126+
}
127+
& ul, & ol {
128+
@apply ml-4 my-1;
129+
}
130+
& ul {
131+
@apply list-disc;
132+
}
133+
& ol {
134+
@apply list-decimal;
135+
}
136+
& li {
137+
@apply my-0.5;
138+
}
139+
& code {
140+
@apply bg-charcoal-700 px-1 py-0.5 rounded text-text-bright font-mono;
141+
}
142+
& pre {
143+
@apply bg-charcoal-700 p-2 rounded my-2 overflow-x-auto;
144+
}
145+
& pre code {
146+
@apply bg-transparent p-0;
147+
}
148+
& blockquote {
149+
@apply border-l-2 border-charcoal-600 pl-3 my-2 italic;
150+
}
151+
& a {
152+
@apply text-blue-400 hover:underline;
153+
}
154+
& strong {
155+
@apply font-semibold text-text-bright;
156+
}
157+
& em {
158+
@apply italic;
159+
}
160+
& hr {
161+
@apply my-2 border-charcoal-600;
162+
}
163+
& table {
164+
@apply w-full my-2 border-collapse;
165+
}
166+
& th, & td {
167+
@apply border border-charcoal-600 px-2 py-1 text-left;
168+
}
169+
& th {
170+
@apply bg-charcoal-700 font-semibold;
171+
}
172+
}

apps/webapp/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
"@heroicons/react": "^2.0.12",
5757
"@internal/cache": "workspace:*",
5858
"@internal/redis": "workspace:*",
59-
"@internal/tsql": "workspace:*",
6059
"@internal/run-engine": "workspace:*",
6160
"@internal/schedule-engine": "workspace:*",
6261
"@internal/tracing": "workspace:*",
62+
"@internal/tsql": "workspace:*",
6363
"@internal/zod-worker": "workspace:*",
6464
"@internationalized/date": "^3.5.1",
6565
"@kapaai/react-sdk": "^0.1.3",
@@ -201,10 +201,11 @@
201201
"simplur": "^3.0.1",
202202
"slug": "^6.0.0",
203203
"socket.io": "4.7.4",
204-
"sql-formatter": "^15.4.10",
205204
"socket.io-adapter": "^2.5.4",
206205
"sonner": "^1.0.3",
206+
"sql-formatter": "^15.4.10",
207207
"sqs-consumer": "^7.4.0",
208+
"streamdown": "^1.4.0",
208209
"superjson": "^2.2.1",
209210
"tailwind-merge": "^1.12.0",
210211
"tailwind-scrollbar-hide": "^1.1.7",
@@ -290,4 +291,4 @@
290291
"engines": {
291292
"node": ">=18.19.0 || >=20.6.0"
292293
}
293-
}
294+
}

pnpm-lock.yaml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)