Skip to content

Commit 2f8ab95

Browse files
authored
feat: strip markdown in messages table (#336)
1 parent 38715de commit 2f8ab95

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

package-lock.json

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"react-markdown": "^9.0.1",
5050
"react-router-dom": "^7.1.1",
5151
"react-syntax-highlighter": "^15.6.1",
52+
"remark": "^15.0.1",
5253
"remark-gfm": "^4.0.0",
54+
"strip-markdown": "^6.0.0",
5355
"tailwind-merge": "^2.5.5",
5456
"tailwind-variants": "^0.3.1",
5557
"tailwindcss-animate": "^1.0.7",

src/features/dashboard-messages/components/table-messages.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
TooltipTrigger,
1212
} from '@stacklok/ui-kit'
1313
import { Alert, Conversation, QuestionType } from '@/api/generated'
14+
import { remark } from 'remark'
15+
import strip from 'strip-markdown'
1416

1517
import { useClientSidePagination } from '@/hooks/useClientSidePagination'
1618
import { TableAlertTokenUsage } from './table-alert-token-usage'
@@ -34,9 +36,11 @@ import { formatTime } from '@/lib/format-time'
3436
import { isAlertPii } from '@/lib/is-alert-pii'
3537

3638
const getPromptText = (conversation: Conversation) => {
37-
return (conversation.question_answers[0]?.question?.message ?? 'N/A')
38-
.trim()
39-
.slice(0, 200) // arbitrary slice to prevent long prompts
39+
const markdownSource =
40+
conversation.question_answers[0]?.question?.message ?? 'N/A'
41+
const fullText = remark().use(strip).processSync(markdownSource)
42+
43+
return fullText.toString().trim().slice(0, 200) // arbitrary slice to prevent long prompts
4044
}
4145

4246
function getTypeText(type: QuestionType) {

0 commit comments

Comments
 (0)